我是靠谱客的博主 喜悦盼望,这篇文章主要介绍CodeForces 217A Ice Skating(DFS),现在分享给大家,希望可以做个参考。

判断联通快个数  答案为个数减一


复制代码
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
#include<iostream> #include<cstdio> #include<algorithm> #include<cstdlib> #include<cmath> #include<string.h> #include<cstring> #include<string> #include<map> #include<set> #include<vector> #include<queue> using namespace std; typedef long long ll; int ans[120]; #define sp system("pause") #define mt(dp) memset(dp,0,sizeof dp) int from[120]; int posx[120]; int posy[120]; int n; void dfs(int x,int cot) { from[x]=cot; for(int i=0;i<n;i++) { if(!from[i]&&(posx[x]==posx[i]||posy[x]==posy[i])) dfs(i,cot); } } int main() { cin>>n; memset(from,0,sizeof from); for(int i=0;i<n;i++) { cin>>posx[i]>>posy[i]; } int cot=0; for(int i=0;i<n;i++) { if(!from[i]) { cot++; dfs(i,cot); } } cout<<cot-1<<endl; return 0; }


最后

以上就是喜悦盼望最近收集整理的关于CodeForces 217A Ice Skating(DFS)的全部内容,更多相关CodeForces内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(74)

评论列表共有 0 条评论

立即
投稿
返回
顶部