首页 > 其他 > 详细

CF 1465C Peaceful Rooks

时间:2021-01-18 14:42:08      阅读:109      评论:0      收藏:0      [点我收藏+]
 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 const int N = 1e5 + 10;
 4 int f[N];
 5 
 6 inline int find(int x)
 7 {
 8     return    (f[x] == x) ? x : f[x] = find(f[x]);
 9 }
10 
11 int main(){
12     int t; cin >> t;
13     while(t--)
14     {
15         int n, m; cin >> n >> m;
16         for(int i = 1 ; i <= n ; i++){
17             f[i] = i;
18         }
19         int res = 0;
20         for(int i = 1 ; i <= m ; i++){
21             int x, y; cin >> x >> y;
22             if(x == y)    continue;
23             if(find(x) != find(y)){
24                 res += 1;
25                 f[y] = x;
26             }else{
27                 res += 2;
28             }
29         }
30         cout << res << endl;
31     }
32     
33     return 0;
34 }

 

CF 1465C Peaceful Rooks

原文:https://www.cnblogs.com/ecustlegendn324/p/14292097.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!