-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1053.cpp
66 lines (62 loc) · 1.41 KB
/
1053.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
//
// 1053.cpp
// 算法
//
// Created by 王怡凡 on 17/3/1.
// Copyright © 2017年 王怡凡. All rights reserved.
//
#include<cstdio>
#include<vector>
#include<algorithm>
using namespace std;
int n,m,s;
const int maxn = 110;
int path[maxn];
struct node {
int weight;
vector<int> childs;
}Nodes[maxn];
bool cmp(int a, int b) {
return Nodes[a].weight > Nodes[b].weight;
}
void DFS(int index, int numNode, int sum) {
if(sum>s) {
return ;
}
if(sum==s) {
if(Nodes[index].childs.size()!=0) {
return ;
}
for(int i=0;i<numNode;i++) {
printf("%d",Nodes[path[i]].weight);
if(i<numNode-1) {
printf(" ");
} else {
printf("\n");
}
}
return ;
}
for(int i=0;i<Nodes[index].childs.size();i++) {
int child = Nodes[index].childs[i];
path[numNode] = child;
DFS(Nodes[index].childs[i],numNode+1,sum+Nodes[child].weight);
}
}
int main() {
int i,pr,j,k,child;
scanf("%d%d%d",&n,&m,&s);
for(i=0;i<n;i++) {
scanf("%d",&Nodes[i].weight);
}
for(i=0;i<m;i++) {
scanf("%d%d",&pr,&k);
for(j=0;j<k;j++){
scanf("%d",&child);
Nodes[pr].childs.push_back(child);
sort(Nodes[pr].childs.begin(),Nodes[pr].childs.end(),cmp);
}
}
DFS(0,1,Nodes[0].weight);
return 0;
}