//看了y总的思路之后自己写的,存储用的vector邻接表,存入数据之后,写一个先序遍历DFS()
//#include< iostream>
//#include< cstring>
//#include< algorithm>
//#include< vector>
//using namespace std;
const int N = 110;
int w[N];
vector< int>tree[N];
int n, m, S;
vector< vector< int>>path;// 存储所有路径
void dfs(int root, int sum, vector< int>s)
{
if (tree[root].size() != 0)//非叶子结点
{
for (int val : tree[root])
{
s.push_back(w[val]);
dfs(val, sum + w[val], s);//递归(传参)
s.pop_back();
}
}
else
{
if (sum == S)
path.push_back(s);
return;//递归出口
}
}
int main()
{
cin >> n >> m >> S;
for (int i = 0; i < n; i++)
cin >> w[i];
int id, num, temp;
while (m--)
{
cin >> id >> num;
for (int i = 0; i < num; i++)
{
cin >> temp;
tree[id].push_back(temp);
}
}
vector< int>ss;
ss.push_back(w[0]);
dfs(00, w[0], ss);
sort(path.begin(), path.end(), greater< vector< int>>());//字典序排序,STL默认比较函数是less< class>(),写了一遍发现不对就改了greater< class>()
for (auto i : path)
{
for (int j = 0; j < i.size(); j++)
{
cout << i[j];
if (j != i.size() - 1)
cout << ' ';
}
cout << endl;
}
/*for (auto h : path)//写了一般的测试部分
{
for (int k : h)
cout << k << ' ';
cout << endl;
}*/
return 0;
}