fork download
  1.  
  2.  
  3. #include<bits/stdc++.h>
  4. #include<ext/pb_ds/assoc_container.hpp>
  5. #include<ext/pb_ds/tree_policy.hpp>
  6. using namespace std;
  7. using namespace __gnu_pbds;
  8. #define int long long
  9. typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> PBDS;
  10.  
  11. bool isPrime(int n)
  12. {
  13.  
  14. if (n <= 1)
  15. return false;
  16.  
  17.  
  18. for (int i = 2; i < n; i++)
  19. if (n % i == 0)
  20. return false;
  21. return true;
  22. }
  23.  
  24. bool palind(string s){
  25. int i = 0;
  26. int j = s.size()-1;
  27. while(i<j){
  28. if(s[i] == s[j]){
  29. i++;
  30. j--;
  31. }
  32. else{
  33. return false;
  34. }
  35. }
  36. return true;
  37. }
  38. bool check(int i,int k){
  39. if(i*(i+1) == 2*k){
  40. return true;
  41. }
  42. return false;
  43. }
  44. signed main(){
  45. ios::sync_with_stdio(0);
  46. cin.tie(0);
  47. cout.tie(0);
  48. cout<<fixed; cout<<setprecision(10);
  49. int t;
  50. cin>>t;
  51. while(t--){
  52. int n;
  53. cin>>n;
  54. int c = 1;
  55. map<int,int> m;
  56. for(int i = 0;i<n;i++){
  57. int s;
  58. cin>>s;
  59. for(int j =0;j<s;j++){
  60. int a;
  61. cin>>a;
  62. m[a] = c;
  63. }
  64. c++;
  65. }
  66. vector<int> v(n,0);
  67. for(auto i : m){
  68. if(i.second <= n){
  69. v[i.second-1] = i.first;
  70. }
  71. }
  72. int b =1;
  73. for(int i =0;i<n;i++){
  74. if(v[i] == 0){
  75. b = 0;
  76. }
  77. }
  78. if(b == 0){
  79. cout<<-1<<endl;
  80. }
  81. else{
  82. for(int i =0;i<n;i++){
  83. cout<<v[i]<<" ";
  84. }
  85. cout<<endl;
  86. }
  87. }
  88. return 0;
  89. }
  90.  
  91.  
Success #stdin #stdout 0.01s 5436KB
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
8 9 4 
-1
2 1 4 3