#include<cstdio>
#include<vector>
#include<algorithm>
using namespace std;
const int MAXN = 110;
struct node{
int weight;
vector<int> child;
} Node[MAXN];
bool cmp(int a, int b){
return Node[a].weight > Node[b].weight;
}
int n, m, S; //结点数、非叶子结点数、给定的和
int path[MAXN]; //记录路径
//当前访问结点为index,numNode为path上的结点个数,sum为当前的结点点权和
void DFS(int index, int numNode, int sum){
if(sum > S) return;
if(sum == S){
if(Node[index].child.size() != 0) return; //还没到叶子结点,直接返回
for(int i = 0; i < numNode; i++){ //到达叶子结点,输出path中的完整路径
printf("%d", Node[path[i]].weight);
if(i < numNode - 1) printf(" ");
else printf("\n");
}
return;
}
for(int i = 0; i < Node[index].child.size(); i++){ //枚举所有子结点
int child = Node[index].child[i]; //结点index的第i的子结点编号
path[numNode] = child; //将结点child加到路径path末尾
DFS(child, numNode + 1, sum + Node[child].weight);
}
}
int main(){
scanf("%d%d%d", &n, &m, &S);
for(int i = 0; i < n; i++){
scanf("%d", &Node[i].weight);
}
int id, k, child;
for(int i = 0; i < m; i++){
scanf("%d%d", &id, &k); //结点编号、孩子个数
for(int j = 0; j < k; j++){
scanf("%d", &child);
Node[id].child.push_back(child);
}
//将子结点按权值从大到小排序
sort(Node[id].child.begin(), Node[id].child.end(), cmp);
}
path[0] = 0; //路径的第一个结点设置为0号结点
DFS(0, 1, Node[0].weight);
return 0;
}
08-15
112
10-22
3861