struct node{
int data;
node* lchild;
node* rchild;
}
node* root = NULL;
node* newNode(int v){
node* Node = new node;
Node->data = v;
Node->lchild = Node->rchild =NULL;
return Node;
}
void search(node* root,int x,int newdata)
{
if(root == NULL){
return;
}
if(root->data == x){
root ->data = newdata;
}
search(root->lchild,x,newdata);
search(root->rchild,x,newdata);
}
void insert(node* &root,int x)
{
if(root == NULL){
root = newNode(x);
return;
}
if(由二叉树的性质,x插在左子树){
insert(root->lchild,x);
}
else{
insert(root->rchild,x);
}
}
node* Create(int data[],int n)
{
node* root = NULL;
for(int i=0;i<n;i++)
insert(root,data[i]);
return root;
}
void preorder(node* root){
if(root == NULL)
return;
printf("%d\n",root->data);
preorder(root->lchild);
preorder(root->rchild);
}
struct node{
int data;
int child[N];
}Node[N];
int idx;
int newNode(int v)
{
Node[idx].data = v;
Node[idx].child.clear();
return idx++;
}
void preorder(int root)
{
cout<<Node[root].data;
for(int i=0;i<Node[root].child.size();i++)
preorder(Node[root].child[i]);
}
void LayerOrder(int root){
queue<int> Q;
Q.push(root);
while(!Q.empty())
{
int front = Q.front();
cout<<Node[front].data;
Q.pop();
for(int i =0 ;i < Node[front].child.size();i++)
Q.push(Node[front].child[i]);
}
}
#include<bits/stdc++.h>
using namespace std;
const int N =110;
struct node{
int weight;
vector<int> child;
}Node[N];
bool cmp(int a,int b){
return Node[a].weight>Node[b].weight;
}
int n,m,s;
int path[N];
void DFS(int idx,int numNode,int sum){
if(sum > s) return;
if(sum == s){
if(Node[idx].child.size()!=0) return;
for(int i = 0;i<numNode;i++){
printf("%d",Node[path[i]].weight);
if(i < numNode - 1) printf(" ");
else printf("\n");
}
return;
}
for(int i=0;i < Node[idx].child.size();i++){
int child = Node[idx].child[i];
path[numNode] = child;
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%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;
DFS(0,1,Node[0].weight);
return 0;
}