fork download
  1. #include <iostream>
  2. #include <set>
  3. using namespace std;
  4.  
  5. multiset <pair <unsigned int, unsigned int>> M;
  6. multiset <pair <unsigned int, unsigned int>>::iterator it;
  7.  
  8. int main() {
  9. unsigned int t, n, a, b;
  10. cin >> t;
  11. while (t != 0) {
  12. cin >> n;
  13. M.clear();
  14. for (int i = 0; i < n; i++) {
  15. cin >> a >> b;
  16. if ((it = M.find (make_pair(b, a))) == M.end()) {
  17. M.insert (make_pair(a, b));
  18. } else M.erase(it);
  19. }
  20. (M.empty()) ? cout << "YES" << endl : cout << "NO" << endl;
  21. t--;
  22. }
  23.  
  24. return 0;
  25. }
Success #stdin #stdout 0s 4412KB
stdin
2
10
1 2
2 1
3 4
4 3
100 200
200 100
57 2
2 57
1 2
2 1
10
1 2
3 4
5 6
7 8
9 10
11 12
13 14
15 16
17 18
19 20
stdout
YES
NO