-
Notifications
You must be signed in to change notification settings - Fork 0
/
uva10763.cpp
80 lines (60 loc) · 1.56 KB
/
uva10763.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#include <limits.h>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>
#include <list>
#include <queue>
#include <map>
#include <string>
#include <algorithm>
#include <bitset>
//#include <unordered_map>
using namespace std;
typedef pair<int, int> ii;
#define traverse(c, it) \
for (map<ii, int>::iterator it = c.begin(); it != c.end(); it++)
int N;
map<ii, int> edges;
map<ii, int> result;
vector<ii> all;
int main() {
while(true) {
cin >> N;
if(N == 0) {
break;
}
edges.clear();
result.clear();
int start, end;
bool match = true;
for(int i = 0; i < N; i++) {
cin >> start >> end;
ii current = make_pair(start, end);
if(edges.find(current) == edges.end()) {
edges.insert(make_pair(current, 1));
all.push_back(current);
} else {
map<ii, int>::iterator it = edges.find(current);
it->second++;
}
}
for(int i = 0; i < all.size(); i++) {
ii start = all[i];
ii end = make_pair(start.second, start.first);
map<ii, int>::iterator it1 = edges.find(start);
map<ii, int>::iterator it2 = edges.find(end);
if(it1->second != it2->second) {
match = false;
break;
}
}
if(match) {
cout << "YES" << endl;
} else {
cout << "NO" << endl;
}
}
return 0;
}