#include<vector>
#include<algorithm>
#include<iostream>
using namespace std;
typedef struct Node{
int weight;
vector<Node*> vChild;
}Node;
int N,M,Weight;
vector<int> solution;
bool cmp(Node* a,Node* b){
return a->weight > b->weight;
}
void DFS(Node* curNode,int cur)
{
cur += curNode->weight;
if (curNode->vChild.size() == 0)//leaf and find
{
if (cur == Weight)
{
for (int i = 0; i < solution.size(); ++i)
{
if(i != solution.size()-1)
printf("%d ", solution[i]);
else printf("%d\n", solution[i]);
}
}
return;
}
else if (curNode->vChild.size() > 0)
{
if (cur > Weight)
return;
else
{
sort(curNode->vChild.begin(), curNode->vChild.end(), cmp);
for (int i = 0; i < curNode->vChild.size(); ++i)
{
solution.push_back(curNode->vChild[i]->weight);
DFS(curNode->vChild[i], cur);
solution.pop_back();
}
}
}
}
int main(){
cin>>N>>M>>Weight;
vector<Node*> nodeMap(N);
for(int i=0;i<N;i++)
{
nodeMap[i]=new Node;
cin>>nodeMap[i]->weight;
}
int id,t,n;
for(int i=0;i<M;i++){
cin>>id>>n;
//nodeMap[t]->vChild = new Node;
while(n--){
cin>>t;
if (id >= 0 && id < N && t >= 0 && t < N)
nodeMap[id]->vChild.push_back(nodeMap[t]);
}
}
solution.push_back(nodeMap[0]->weight);
int cur = 0;
DFS(nodeMap[0], cur);
//release memory
for (int i = 0; i < N; ++i)
delete nodeMap[i];
return 0;
}
#include<algorithm>
#include<iostream>
using namespace std;
typedef struct Node{
int weight;
vector<Node*> vChild;
}Node;
int N,M,Weight;
vector<int> solution;
bool cmp(Node* a,Node* b){
return a->weight > b->weight;
}
void DFS(Node* curNode,int cur)
{
cur += curNode->weight;
if (curNode->vChild.size() == 0)//leaf and find
{
if (cur == Weight)
{
for (int i = 0; i < solution.size(); ++i)
{
if(i != solution.size()-1)
printf("%d ", solution[i]);
else printf("%d\n", solution[i]);
}
}
return;
}
else if (curNode->vChild.size() > 0)
{
if (cur > Weight)
return;
else
{
sort(curNode->vChild.begin(), curNode->vChild.end(), cmp);
for (int i = 0; i < curNode->vChild.size(); ++i)
{
solution.push_back(curNode->vChild[i]->weight);
DFS(curNode->vChild[i], cur);
solution.pop_back();
}
}
}
}
int main(){
cin>>N>>M>>Weight;
vector<Node*> nodeMap(N);
for(int i=0;i<N;i++)
{
nodeMap[i]=new Node;
cin>>nodeMap[i]->weight;
}
int id,t,n;
for(int i=0;i<M;i++){
cin>>id>>n;
//nodeMap[t]->vChild = new Node;
while(n--){
cin>>t;
if (id >= 0 && id < N && t >= 0 && t < N)
nodeMap[id]->vChild.push_back(nodeMap[t]);
}
}
solution.push_back(nodeMap[0]->weight);
int cur = 0;
DFS(nodeMap[0], cur);
//release memory
for (int i = 0; i < N; ++i)
delete nodeMap[i];
return 0;
}