hdu 2120 Ice_cream's world I
来源:互联网 发布:功率串联和并联的算法 编辑:程序博客网 时间:2024/05/22 00:22
本题链接:http://acm.hdu.edu.cn/showproblem.php?pid=2120
本题用并查集判断环的个数,AC代码:
#include<stdio.h>int per[1100];int flag;void init(){for(int i=0;i<1100;i++)per[i]=i;}int find(int x){int r=x;while(r!=per[r])r=per[r];int j,i=x;while(i!=r){j=per[i];i=j;per[i]=r;}return r;}void join(int a,int b){int fa=find(a);int fb=find(b);if(fa!=fb)per[fa]=fb;else flag++;}int main(){int n,m;int a,b;while(scanf("%d%d",&n,&m)!=EOF){init();flag=0;for(int i=0;i<m;i++){scanf("%d%d",&a,&b);join(a,b);}printf("%d\n",flag);}return 0;}
0 0
- hdu 2120 Ice_cream's world I
- HDU 2120 Ice_cream's world I
- hdu 2120 Ice_cream's world I
- hdu-2120-Ice_cream's world I
- hdu 2120 Ice_cream's world I
- hdu 2120 Ice_cream's world I
- HDU-2120-Ice_cream's world I
- HDU 2120 Ice_cream's world I
- hdu-2120 Ice_cream's world I
- hdu 2120 Ice_cream's world I
- hdu 2120 Ice_cream's world I
- HDU 2120 Ice_cream's world I
- HDU 2120 Ice_cream's world I
- hdu 2120 Ice_cream's world I
- hdu 2120 (Ice_cream's world I)
- 【HDU 2120 Ice_cream's world I】
- HDU 2120Ice_cream's world I
- HDU-2120 Ice_cream's world I
- 360踩在3721尸体上扶摇直上(转载)
- 国内外知名Android开发者GitHub、Blog
- python设计模式之Null模式
- 【HttpClient4.5中文教程】【第一章 :基础】1.1执行请求(一)
- 函数柯里化or not
- hdu 2120 Ice_cream's world I
- 输出等腰三角形的*
- JAVA基础点汇总(三)
- python设计模式之桥接模式
- Struts2 的ModelDriven 一 —— 传值
- Incorrect string value: '' for column '' at row 1
- android开发的小知识--选择编译
- 畅通工程
- hdu 3473 Minimum Sum