fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. vector<int> ke[1001];
  4. int main(){
  5. int n; // n là d?nh
  6. cin >> n ;
  7. for(int i = 1 ; i <= n ; i++){
  8. string s;
  9. getline(cin,s);
  10. stringstream ss(s);
  11. string token;
  12. while(ss >> token){
  13. ke[i].push_back(stoi(token));
  14. }
  15. }
  16. for(int i = 1 ; i <= n ; i++){
  17. sort(ke[i].begin(),ke[i].end());
  18. }
  19. int a[n+1][n+1];
  20. for(int i = 1 ; i<= n ; i++){
  21. for(int j = 1 ; j <= ke[i].size() ; j++){
  22. a[i][j] = 1 ;
  23. }
  24. }
  25. for(int i = 1 ; i <= n ; i++){
  26. for(int j = 1 ; j <= n ; j++){
  27. if(a[i][j] == 1){
  28. a[i][j] = 0 ;
  29. a[j][i] = 0;
  30. cout << i << " " << j << endl;
  31. }
  32. }
  33. }
  34. }
Success #stdin #stdout 0.01s 5284KB
stdin
5
4
3 4 5
2 5
1 2
2 3
stdout
2 1
3 1
3 2
3 3
4 1
4 2
5 1
5 2