05-树8 File Transfer(25 point(s))
2017-10-31 14:46
549 查看
题目位置
看了老师的 各种骚操作0 0
路径压缩 和 秩的运算
看了老师的 各种骚操作0 0
路径压缩 和 秩的运算
#include <stdio.h> #include <stdlib.h> #include <math.h> int *computer; int N; void Connection(int position,int connection); void Check(int position,int connection); void Check_NextWork(); int find(int position); int main(){ int i,j; scanf("%d",&N); computer = (int*)malloc((N+1)*sizeof(int)); for(i=0;i<N+1;i++){ computer[i]=-1; } char s[2]; int position,connection; do{ scanf("%s",&s); switch(s[0]){ case 'I':Connection(position,connection);break; case 'C':Check(position,connection);break; } }while(s[0]!='S'); Check_NextWork(computer,N); } int find(int position){ if(computer[position]<0)return position; else return computer[position] = find(computer[position]); } void Connection(int position,int connection){ scanf("%d %d",&position,&connection); int i=find(position); int j=find(connection); if(computer[i]>computer[j])computer[i]=j,computer[j]-=1; else computer[j]=i,computer[i]-=1; } void Check(int position,int connection){ scanf("%d %d",&position,&connection); int i=find(position); int j=find(connection); if(i==j)printf("yes\n"); else printf("no\n"); } void Check_NextWork(){ int counter=0; int i; for(i=1;i<N+1;i++){ if(computer[i]<0)counter++; } if(counter==1)printf("The network is connected."); else printf("There are %d components.",counter); }
相关文章推荐
- 05-树8 File Transfer(25 分)
- 05-树7. File Transfer (25)
- PAT : 05-树7. File Transfer (25)
- 05-树8 File Transfer(25 分)
- 05-树7. File Transfer (25)
- PAT 05-树7. File Transfer (25)
- 05-树8 File Transfer(25 分)
- 05-树8 File Transfer(25 分)
- 05-树8 File Transfer (25分)
- File Transfer(25 分)
- 7-26 File Transfer(25 分)
- 05-树8 File Transfer
- 05-树9 File Transfer (25分)
- 05-树8 File Transfer【并查集】
- PAT 04-2. File Transfer (25) (并查集)
- 04-2. File Transfer (25)并查集
- 05-树9 File Transfer
- 05-树8 File Transfer
- TCP-IP详解卷1-15:TFTP(Trivial File Transfer Protocol):简单文件传送协议
- hadoop2.7.2学习笔记05-hadoop文件系统API定义-hadoop文件系统类org.apache.hadoop.fs.FileSystem