代码:
#include<bits/stdc++.h>
using namespace std;
#define qwq ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
int n, m, b[100010];
map<string, vector<int>> mp;
int main()
{
qwq;
cin >> n;
for (int i = 1; i <= n; i++)
{
int l;
cin >> l;
for (int j = 1; j <= l; j++)
{
string word;
cin >> word;
mp[word].push_back(i);
}
}
cin >> m;
for (int i = 1; i <= m; i++)
{
string found;
cin >> found;
memset (b, 0, sizeof(b));
for (int j = 0; j < mp[found].size(); j++)
{
if (b[mp[found][j]] == 0)
{
cout << mp[found][j] << " ";
mp[found][j] = 1;
}
}
cout << endl;
}
return 0;
}