fork download
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4. #include <queue>
  5. #include <map>
  6. #include <set>
  7. #include <bits/stdc++.h>
  8. using namespace std;
  9. #include <ext/pb_ds/assoc_container.hpp>
  10. using namespace __gnu_pbds;
  11. template <class T>
  12. using orderStaticTree =
  13. tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
  14.  
  15. #define ll long long
  16.  
  17. #define saleh \
  18.   ios_base::sync_with_stdio(false); \
  19.   cin.tie(nullptr);
  20.  
  21. const int md = 1e9 + 7;
  22.  
  23. int main()
  24. {
  25. saleh;
  26. int t;
  27. cin >> t;
  28. while (t--)
  29. {
  30. int n;
  31. cin >> n;
  32. vector<int> ans(2 * n + 2);
  33. map<int, int> seen;
  34. for (int i = 1; i <= n; i++)
  35. {
  36. for (int j = 1; j <= n; j++)
  37. {
  38. int x;
  39. cin >> x;
  40. ans[i + j] = x;
  41. seen[x] = 1;
  42. }
  43. }
  44.  
  45. for (int i = 1; i <= 2 * n; i++)
  46. {
  47. if (seen.find(i) == seen.end())
  48. {
  49. ans[1] = i;
  50. break;
  51. }
  52. }
  53. for (int i = 1; i <= 2 * n; i++)
  54. cout << ans[i] << " ";
  55. cout << endl;
  56. }
  57.  
  58. return 0;
  59. }
Success #stdin #stdout 0.01s 5280KB
stdin
Standard input is empty
stdout
Standard output is empty