UVA-10763 Foreign Exchange

 1 #include <stdio.h>
 2 #include <iostream>
 3 #include <algorithm>
 4 #include <map>
 5 
 6 using namespace std;
 7 
 8 int main ()
 9 {
10     int N;
11     while(cin >> N && N != 0)
12     {
13         map<int,int> m;
14         while(N--)
15         {
16             int a,b;
17             cin >> a >> b;
18             if(m.count(a))
19             {
20                 m[a] --;
21             }
22             else
23             {
24                 m[a] = -1;
25             }
26             if(m.count(b))
27             {
28                 m[b] ++;
29             }
30             else
31             {
32                 m[b] = 1;
33             }
34         }
35         int flag = 1;
36         for(auto Ptr = m.begin();Ptr != m.end();Ptr ++)
37         {
38             if(Ptr->second!=0)
39             {
40                 flag = 0;
41                 break;
42             }
43         }
44         if(flag)
45             cout << "YES" << endl;
46         else
47             cout << "NO" << endl;
48     }
49     return 0;
50 }

 

posted @ 2018-09-29 14:59  Asurudo  阅读(113)  评论(0编辑  收藏  举报