你怎么那么熟练啊?
#include <cstdio>
#include <queue>
#include <algorithm>
#include <iostream>
#include <time.h>
#include <vector>
using namespace std;
const int maxn = 111;
struct Node{
int weight;
vector<int> child;
}node[maxn];
int N,M,S;
vector<int> path;
bool cmp(int a,int b)
{
return node[a].weight>node[b].weight;
}
void dfs(int root, int ww)
{
if(ww>S)
return;
if(node[root].child.size()==0)
{
if(ww == S)
{
for(int i=0;i<path.size();i++)
{
if(i==0)
printf("%d",path[i]);
else
printf(" %d",path[i]);
}
printf("\n");
}
}
sort(node[root].child.begin(), node[root].child.end(), cmp);
for(int i=0;i<node[root].child.size();i++)
{
int tmp = node[root].child[i];
path.push_back(node[tmp].weight);
dfs(tmp, ww + node[tmp].weight);
path.pop_back();
}
}
int main()
{
int i,j,k,ch,tmp;
scanf("%d %d %d",&N,&M,&S);
for(i=0;i<N;i++)
scanf("%d",&node[i].weight);
for(i=0;i<M;i++)
{
scanf("%d %d",&j,&k);
for(ch=0;ch<k;ch++)
{
scanf("%d",&tmp);
node[j].child.push_back(tmp);
}
}
path.clear();
path.push_back(node[0].weight);
dfs(0,node[0].weight);
return 0;
}