hiho week 49 register

Ended

Participants:509

Verdict:Accepted
Score:100 / 100
Submitted:2015-06-07 15:00:12

Lang:GCC

Edit
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
#include <stdio.h>
#include <string.h>
int island[10001];
int unionset[10001];
int findEnd(int start){
    int end = unionset[start];
    while(unionset[end]!=end)
        end = unionset[end];
    return end;
}
int main()
{
    int N,M;
    scanf("%d %d",&N,&M);
    memset(island,0,sizeof(int)*(N+1));
    memset(unionset,0,sizeof(int)*(N+1));
    int i=0,b1,b2;
    for(;i<M;i++){
        scanf("%d %d",&b1,&b2);
        island[b1]++;
        island[b2]++;
        if(unionset[b1]==0&&unionset[b2]==0){
            unionset[b1] = b1;
            unionset[b2] = b1;
        }else if(unionset[b1]!=0&&unionset[b2]!=0){
            int end1 = findEnd(b1);
            int end2 = findEnd(b2);
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX