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