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
/* and check set int par[max_n];int rank[max_n};//initialize N elements void init (int N) {for (int i=0;i<n;i++) {par[i]=i; rank[i]=0; }}//the root int of the query tree, find (int x) {if (par[x]==x) return x;else return Par[x]=find (Par[x]);} Merge x and y belong to the collection void unite (int x,int y) {x=find (x); Y=find (y); if (x==y) return; if (Rank[x]<rank[y]) par[x]=y;else{par[y] =x;if (Rank[x]==rank[y]) rank[x]++;} }//To determine if x and Y belong to the same set bool Same (int x,int y) {return find (x) ==find (y);} */#include <stdio.h> #include <string.h> #define MAX 1002int degree[max];int map[max];void init (int n) {for (int i=0;i<=n;i++) map[i]=i;} int find (int i) {return (map[i]==i) I:find (Map[i]);} int main () {int n,k,i,j,q,a,b; int flage,cnt; scanf ("%d", &k); while (k--) {scanf ("%d%d", &n,&q); flage=0; memset (degree,0,sizeof (degree)); Init (n); for (i=0; i<q; i++) {scanf ("%d%d", &a,&b); degree[a]++; degree[b]++; Map[find (a)]=map[find (b)]; } cnt=0; for (i=1;i<=n;i++) {if (map[i]==i) cnt++; if (degree[i]%2==1) flage++; } if (cnt==1&& (flage==0| | flage==2)) printf ("yes\n"); else printf ("no\n"); } return 0;}
A stroke problem