cpp
复制代码
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cstring>
using namespace std;
const int K = 2510;
const int maxn = 40010;
vector<int> courses[K];
char names[maxn][5];
bool cmp(int a, int b){
return strcmp(names[a], names[b]) < 0;
}
int main() {
int N,M;
scanf("%d%d", &N, &M);
for(int i = 0; i < N; i++){
int num;
scanf("%s %d", names[i], &num);
for(int j = 0; j < num; j++){
int id;
scanf("%d", &id);
courses[id].push_back(i);
}
}
for(int i = 1; i <= M; i++){
printf("%d %d\n", i, courses[i].size());
sort(courses[i].begin(), courses[i].end(), cmp);
for(int j = 0; j < courses[i].size(); j++){
printf("%s\n", names[courses[i][j]]);
}
}
return 0;
}