Files
python/TangDou/LuoGuBook/P3879_Right.cpp
HuangHai 1f397eca87 'commit'
2025-08-30 18:35:01 +08:00

40 lines
978 B
C++

#include <bits/stdc++.h>
using namespace std;
int n, m, cnt;
int flag[500000];
unordered_map<string, int> match;
vector<int> G[100010];
int main() {
cin >> n;
for (int i = 1; i <= n; i++) {
int opt;
cin >> opt;
for (int j = 1; j <= opt; j++) {
string op;
cin >> op;
if (!match[op]) {
cnt++;
match[op] = cnt;//映射成数字
G[cnt].push_back(i);
} else {
G[match[op]].push_back(i);
}
}
}
cin >> m;
for (int i = 1; i <= m; i++) {
string opt;
cin >> opt;
memset(flag, 0, sizeof(flag));
for (int j = 0; j < G[match[opt]].size(); j++) {
if (flag[G[match[opt]][j]])continue;//判重
flag[G[match[opt]][j]] = 1;
cout << G[match[opt]][j] << ' ';
}
cout << '\n';
}
return 0;
}