-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathpat-1053.cpp
More file actions
47 lines (47 loc) · 882 Bytes
/
Copy pathpat-1053.cpp
File metadata and controls
47 lines (47 loc) · 882 Bytes
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
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
vector<int>map[100];
vector<int>path;
int cost[100];
void dfs(int start,int cc)
{
if(map[start].size()>0){
if (cc>0){
path.push_back(start);
for(int i=0;i<map[start].size();i++)
dfs(map[start][i],cc-cost[start]);
path.pop_back();
}
}else{
//printf("%d %d \n",cc,start);
if(cc-cost[start]==0){
for(int i=0;i<path.size();i++)
printf("%d ", cost[path[i]]);
printf("%d\n", cost[start]);
}
}
}
bool my(int a,int b)
{
return cost[a]>cost[b];
}
int main()
{
int n, m, s;
scanf("%d %d %d",&n,&m,&s);
for(int i=0;i<n;i++)
scanf("%d", cost+i);
for(int i=0;i<m;i++)
{
int node, num; scanf("%d %d",&node,&num);
for (int j=0;j<num;j++)
{ int c;
scanf("%d",&c); map[node].push_back(c);
}
sort(map[node].begin(), map[node].end(), my);
}
dfs(0,s);
return 0;
}