set的一些小用法

1

 1 #include <cstdio>
 2 #include<iostream>
 3 #include<vector>
 4 #include<set>
 5 using namespace std;
 6 typedef long long LL;
 7  
 8 set<pair<int, int >>s;
 9 int main()
10 {
11     int n;
12     cin >> n;
13      
14     for (int i = 0; i < n - 1; i++)
15     {
16         int a, b;
17         cin >> a >> b;
18         s.insert({ a,b });
19         s.insert({ b,a });
20     }
21     int ans = 0;
22     for (int i = 0; i < n - 1; i++)
23     {
24         int a, b;
25         cin >> a >> b;
26         if (s.count({ a,b }) || s.count({b,a}))
27         {
28             continue;
29         }
30          
31         else
32         {
33             ans++;
34         }
35  
36     }
37     cout << ans << endl;
38 }

 

posted @ 2020-07-31 14:24  古比  阅读(146)  评论(0编辑  收藏  举报