-
- topic information
- run result
- line
- discussion area
Time limit for a stroke problem: theMs | Memory Limit:65535KB Difficulty:4
-
-
Describe
-
Zyc like to play some small games since childhood, including painting a stroke, he would like to ask you to help him write a program, judge whether a figure can use a stroke down.
Rules, all sides can only draw once, can not repeat the painting.
-
-
Input
-
-
the first line has only one positive integer N (n<=10) that represents the number of groups of test data.
The first line of each set of test data has two positive integer p,q (p<=1000,q<=2000), representing how many vertices and lines are in the picture. (number of points from 1 to p)
The subsequent Q line has two positive integers, a, a, B (0<a,b<p) for each line, indicating that there is a connection between the two points numbered a and a.
-
-
Output
-
-
If there is a qualifying connection, output "Yes",
If there are no qualifying lines, output "no".
-
-
Sample input
-
-
24 31 21 31 44 51 22 31 31 43 4
-
-
Sample output
-
-
NoYes
-
-
Source
-
-
[Zhang Yunzun] Original
-
-
Uploaded by
-
-
Zhang Yunzun
#include <stdio.h> #include <string.h>int flag,fa[1005],n,rank[1005];int Find (int x)//Find and compress the path {if (fa[x]!= x) Fa[x]=find (fa[x]); return fa[x];} void Uni (int x,int y)//number of layers of the tree {if (Rank[x]>=rank[y]) {fa[y]=x;rank[x]++;} Else{rank[y]++;fa[x]=y;}} int main () {int ncase,num[1005],v;scanf ("%d", &ncase), while (ncase--) {memset (fa,0,sizeof (FA)); Memset (rank,0, sizeof (rank)); memset (num,0,sizeof (num)); scanf ("%d%d", &n,&v); for (int i=1;i<=n;i++) fa[i]=i,rank[i]=0; for (int i=0;i<v;i++) {int a,b,x,y;scanf ("%d%d", &a,&b), Num[a]++,num[b]++;x=find (a), y=find (b); if (x!=y) Uni (x, y);} int odd=0,sum=0;for (int i=1;i<=n;i++) {if (num[i]%2) odd++;if (fa[i]==i) sum++;} if (odd==0| | Odd==2&&sum==1)//odd=2 is not a ring, odd=2 is a ring, Sum=1 has only one root printf ("yes\n"); elseprintf ("no\n");} return 0;}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Nyoj42 a stroke problem (Euler loop)