5 21 22 31 35 21 23 41 45 21 23 42 5Example Output
samenot surenot sure#include<stdio.h>#include<string.h>#define maxn 100005void init(int n,int a[]){ int i; for(i=1;i<=n;i++) { a[i]=i; }}int f(int a[],int x){ while(a[x]!=x) { x=a[x]; } return x;}void merge(int u,int v,int a[]){ int x,y; x=f(a,u); y=f(a,v); if(x!=y) { a[x]=y; }}int main(){ int i,j,t,n,k,u,v,c,d,count,o,p; int a[maxn]; count=0; memset(a,0,sizeof(a)); while(scanf("%d%d",&n,&k)!=EOF) { init(n,a); while(k--) { scanf("%d%d",&u,&v); merge(u,v,a); } scanf("%d%d",&c,&d); o=f(a,c); p=f(a,d); if(o==p) { printf("same/n"); } else { printf("not sure/n"); } } return 0;}
新闻热点
疑难解答