#include<iostream>
#include<map>
#include<set>
using namespace std;
#define maxn 300001
set<int>info[maxn];
map<int, string>iTos;
map<string, int>sToi;
int c = 1;
int main() {
int N, K;
cin >> N >> K;
for (int i = 1; i <= K; i++) {
int course; int number;
cin >> course>>number;
for (int j = 1; j <= number; j++) {
string name; cin >> name;
if (sToi[name] == 0) {
sToi[name] = c;
iTos[c] = name;
c++;
}
info[sToi[name]].insert(course);
}
}
for (int i = 1; i <= N; i++) {
string ask; cin >> ask; int size = info[sToi[ask]].size();
cout << ask << " " << size;
if (size) {
cout << " ";
for (auto it:info[sToi[ask]]) {
cout << it;
if (it != *(--info[sToi[ask]].end())) cout << " ";
}
}
cout << endl;
}
return 0;
}
maxn定为500001,最后一个测试点内存超限,改成300001后勉强通过了
|