hiho week 49 register

Ended

Participants:509

Verdict:Accepted
Score:100 / 100
Submitted:2015-06-06 21:24:22

Lang:G++

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>
const int maxn=10000+10;
int n,m;
int p[maxn];
int cnt_in[maxn],cnt_out[maxn],cnt_dushu[maxn];
int cha(int x)
{
    return p[x]==x?x:cha(p[x]);
}
void bing(int x,int y)
{
    x=cha(p[x]);
    y=cha(p[y]);
    if(x!=y)
        p[x]=y;
}
int main()
{
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++)
        p[i]=i;
    memset(cnt_dushu,0,sizeof(cnt_dushu));
    for(int i=0;i<m;i++)
    {
        int u,v;
        scanf("%d%d",&u,&v);
        cnt_dushu[v]++;
        cnt_dushu[u]++;
        bing(u,v);
    }
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX