HEU 5015 Eular Graph

 

 1 /**************************************
 2Problem: HEU 5015 Eular Graph
 3Time: 0.0040 s
 4Memory: 236 k 
 5Accepted Time: 2009-04-07 12:57:34
 6Tips: 首尾相连,连成圈 
 7**************************************/

 8 #include  < stdio.h >
 9 #include  < string .h >
10 struct  edge
11 {
12    int i,j;
13}
a[ 1000 ];
14 int  main()
15 {
16    int tt;
17    scanf("%d",&tt);
18    while(tt--)
19    {
20        int n,m,i,b[1000];
21        scanf("%d%d",&n,&m);
22        memset(b,0,sizeof(b));
23        for(i=0;i<m;i++)scanf("%d%d",&a[i].i,&a[i].j);
24        b[0]=1;
25        int count=1;
26        int temp=a[0].i,t=a[0].j;
27        while(1)
28        {
29            for(i=1;i<m;i++)
30            {
31                if(b[i]==0&&t==a[i].i)
32                {
33                    b[i]=1;
34                    t=a[i].j;
35                    count++;
36                }

37            }

38            if(i==m||count==m)break;
39        }

40        if(count==m&&temp==t)printf("yes\n");
41        else printf("no\n");
42    }

43    return 0;
44}

45

 

你可能感兴趣的:(Graph)