fork(10) download
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7. int n;
  8. cin >> n;
  9. int degree[n], xorsum[n];
  10. queue <int> Q;
  11. int used = 0;
  12. for(int i = 0; i < n; ++i)
  13. {
  14. cin >> degree[i] >> xorsum[i];
  15. if (degree[i] == 1)
  16. Q.push(i);
  17. if (degree[i] == 0)
  18. {
  19. if (xorsum[i] != 0)
  20. assert(false);
  21. used++;
  22. }
  23. }
  24. vector < pair<int, int> > ans;
  25. while(!Q.empty())
  26. {
  27. int from = Q.front();
  28. Q.pop();
  29. used++;
  30. if (degree[from] == 0)
  31. {
  32. if (xorsum[from] != 0)
  33. assert(false);
  34. continue;
  35. }
  36. degree[from]--;
  37. int to = xorsum[from];
  38. xorsum[from] = 0;
  39. if (to >= n)
  40. assert(false);
  41. ans.push_back(make_pair(from, to));
  42. xorsum[to] ^= from;
  43. if (degree[to] == 0)
  44. assert(false);
  45. degree[to]--;
  46. if (degree[to] == 1)
  47. Q.push(to);
  48. }
  49. if (used != n)
  50. assert(false);
  51. cout << ans.size() << endl;
  52. for(size_t i = 0; i < ans.size(); ++i)
  53. cout << ans[i].first << " " << ans[i].second << endl;
  54. return 0;
  55.  
  56. }
Runtime error #stdin #stdout 0s 3100KB
stdin
Standard input is empty
stdout
Standard output is empty