fork download
  1. #include <bits/stdc++.h>
  2. #include <unordered_set>
  3. using namespace std;
  4. int main() {
  5. ios_base::sync_with_stdio(false);
  6. int t, n;
  7. cin >> t;
  8. while (t--) {
  9. cin >> n;
  10. unordered_set<int> set, possible, curr;
  11. int temp = n;
  12. int x;
  13. vector<int> p;
  14. while (temp--) {
  15. cin >> x;
  16. p.clear();
  17. int y;
  18. for (int i = 0; i < x; i++) {
  19. cin >> y;
  20. p.push_back(y);
  21. set.insert(p[i]);
  22. curr.insert(p[i]);
  23. }
  24. for (auto itr : set) {
  25. if (curr.find(itr) == curr.end()) {
  26. possible.insert(itr);
  27. }
  28. }
  29. curr.clear();
  30. }
  31. for (int i = 0; i < x; i++) {
  32. possible.insert(p[i]);
  33. }
  34. int c = 0;
  35. for (auto itr : possible) {
  36. if (c == n)
  37. break;
  38. cout << itr << " ";
  39. }
  40. cout << endl;
  41. }
  42. return 0;
  43. }
  44.  
Success #stdin #stdout 0.01s 5396KB
stdin
3
3
4
1 2 4 8
3
2 9 1
2
1 4
2
2
1 2
2
2 1
4
4
1 2 3 4
1
1
1
4
1
3
stdout
1 2 8 9 4 
1 2 
1 2 4 3