fork download
  1. #include <iostream>
  2. #include <vector>
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7. int n;
  8. cin >> n;
  9. vector< vector<int> > a (n, vector<int>(n, 0));
  10.  
  11. bool first = true;
  12.  
  13. for (int d = 0; d < n * n; ++d)
  14. {
  15. int row, col;
  16. cin >> row >> col;
  17. --row;
  18. --col;
  19. if (a[row][col] == 0)
  20. {
  21. if (first)
  22. first = false;
  23. else
  24. cout << " ";
  25.  
  26. cout << d + 1;
  27.  
  28. for (int c = 0; c < n; ++c)
  29. a[row][c] = 1;
  30. for (int r = 0; r < n; ++r)
  31. a[r][col] = 1;
  32. }
  33.  
  34. }
  35.  
  36.  
  37.  
  38. return 0;
  39.  
  40. }
Success #stdin #stdout 0s 3416KB
stdin
3
1 1
2 1
3 3
1 1
1 1
1 1
2 2
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
stdout
1 3 7