#include<stdio.h>
#include<vector>
#include<algorithm>
using namespace std;
int n, m, Sweight;
struct pnode{
int weight;
vector<int> child;
}node[110];
int path[110]={0};
void DFS(int root, int node_num, int weight){
if(weight>Sweight)return ;
if(weight==Sweight && node[root].child.size()==0){
for(int it=0;it<node_num;it++){
printf("%d",node[path[it]].weight);
if(it<node_num-1)printf(" ");
else printf("\n");
}
}
for(int i=0;i<node[root].child.size();i++){
path[node_num]=node[root].child[i];
DFS(node[root].child[i],node_num+1,weight+node[node[root].child[i]].weight);
}
}
bool cmp(int a,int b){
return node[a].weight>node[b].weight;
}
int main(){
int i, j, id, k, temp;
scanf("%d%d%d",&n,&m,&Sweight);//输入权重
for(i=0;i<n;i++)scanf("%d",&node[i].weight);
for(i=0;i<m;i++){
scanf("%d%d",&id,&k);
for(j=0;j<k;j++){
scanf("%d",&temp);
node[id].child.push_back(temp);
}
sort(node[id].child.begin(),node[id].child.end(),cmp);
}
DFS(0,1,node[0].weight);
return 0;
}
PAT-A1053
最新推荐文章于 2022-01-27 19:30:49 发布