More is better&&The Suspects
来源:互联网 发布:cacti监控mysql模板 编辑:程序博客网 时间:2024/04/30 09:43
这两道题非常相似,都是计算一个联通中所有节点的个数,只需要在find中加个计算就可以了
#include<stdio.h>int parent[10000005];int num[10000005];int find(int x){if(x != parent[x])parent[x] = find(parent[x]);return parent[x];}void Merge(int a,int b){int c = find(a);int d = find(b);if(c != d){parent[c] = d;num[d] += num[c];}}int main(){int n,count,max1 = 0;int A,B;while(~scanf("%d",&n)){if(n == 0)printf("1\n");else{for(int i = 1 ; i <= 10000005 ; i++){parent[i] = i;num[i] = 1;}for(int i = 1 ; i <= n ; i++){scanf("%d %d",&A,&B);Merge(A,B);if(A > max1)max1 = A;if(B > max1)max1 = B;}//printf("%d\n",max1);int max = 0;for(int i = 1 ; i <= max1 ; i++){if(num[i] > max){max = num[i];}}printf("%d\n",max);}}return 0;}
阅读全文
0 0
- More is better&&The Suspects
- The more, The Better
- The more, The Better
- The more, The Better
- HDOJ More is better
- hdu More is better
- More is better
- HDU1856:More is better
- HDU1856--More is better
- hdu1856-More is better
- HDU1856:More is better
- hdu1856 More is better
- H - More is better
- More is better
- More is better
- More is better
- More is better
- C - More is better
- 优雅的使用Markdown标记语言
- 不可以在列表模板里面写<? ?>中php开始、结束标签
- 我的android-studio在Ubuntu16.04运行了
- 颜色rgba表示
- 第四天:外边距重叠、css背景设置、float浮动、伪元素
- More is better&&The Suspects
- java 二进制兼容 的解释
- 管理Redo Log
- 学位论文中公式按章节编号“一.1”如何变成“1.1”?
- Python解析JSON
- 分布式事物理论与实践
- 你真的会二分查找吗?
- http三次握手
- 向量范数与机器学习中的正则项