自认为马蜂良好
#include <bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
#define inf 0x3f3f3f3f
using namespace std;
#define pii pair<int, int>
#define pll pair<ll, ll>
#define endl '\n'
#define IOS \
ios::sync_with_stdio(NULL); \
cin.tie(NULL); \
cout.tie(NULL)
#define qwq cout << "qwq" << endl
#define line cout << "------------------" << endl
const int maxn = 1e3 + 5;
int n, m;
string s;
int trie[maxn][maxn][26], tot[maxn];
bool word[maxn][maxn];
void ist(int x, string s)
{
int u = 0;
for (char ch : s)
{
int p = ch - 'a';
if (!trie[x][u][p])
{
trie[x][u][p] = ++tot[x];
}
u = trie[x][u][p];
}
word[x][u] = 1;
}
bool fnd(int x, string s)
{
int u = 0;
for (char ch : s)
{
int p = ch - 'a';
if (!trie[x][u][p])
return 0;
u = trie[x][u][p];
}
return word[x][u];
}
signed main()
{
IOS;
cin >> n;
for (int i = 1; i <= n; i++)
{
int l;
cin >> l;
for (int j = 1; j <= l; j++)
{
cin >> s;
ist(i, s);
}
}
cin >> m;
for (int i = 1; i <= m; i++)
{
cin >> s;
for (int j = 1; j <= n; j++)
{
if (fnd(j, s))
{
cout << j << " ";
}
}
cout << endl;
}
return 0;
}