解法一:模拟

  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. vector<vector<string>> info;
  4. int main() {
  5. ios::sync_with_stdio(false);
  6. cin.tie(0);
  7. int N, K;
  8. cin >> N >> K;
  9. info.resize(K);
  10. string name;
  11. int M, tmp;
  12. for (int i = 0; i < N; ++i) {
  13. cin >> name;
  14. cin >> M;
  15. for (int j = 0; j < M; ++j) {
  16. cin >> tmp;
  17. info[tmp - 1].emplace_back(name);
  18. }
  19. }
  20. int i = 1;
  21. for (auto &list:info) {
  22. cout << i << " " << list.size() << "\n";
  23. ++i;
  24. sort(list.begin(), list.end());
  25. for (auto &student:list) {
  26. cout << student << "\n";
  27. }
  28. }
  29. }