solution #include <iostream> #include <queue> #include <cstring> #include <set> #include <map> using namespace std; const int N = 50010; map<string, set<int>> x1; int idxnumber = 1; int main() { int n, k; scanf("%d %d", &n, &k); for (int i = 1; i <= k; i++) { int num, num2; scanf("%d %d", &num, &num2); for (int i = 1; i <= num2; i++) { string x; cin >> x; x1[x].insert(num); } } for (int i = 1; i <= n; i++) { string x; cin >> x; cout << x << " " << x1[x].size(); for (auto w : x1[x]) { cout << " " << w; } if (i != n) puts(""); } }