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
Analysis: to determine whether a graph can be used in a stroke down: (1) use and check the set to determine whether the graph is connected, (2) determine whether the Euler circuit or Oraton Road (note: The European pull circuit: when and only if each vertex of this graph has even several Oraton road: when and only if there are just two odd vertices)
-
#include <stdio.h> #include <string.h> #include <iostream> #include <algorithm>using namespace Std;int n,m;int pre[1010],a[1010],b[1010];int Find (int x)//Find {int r = x; while (r! = Pre[r]) R = Pre[r]; int i = X,J; while (Pre[i]! = r)//path Compression {j = pre[i]; Pre[i] = r; i = j; } return R;} void join (int x,int y)//merge {int FX = Find (x); int fy = Find (y); if (FX! = FY) pre[fy] = FX;} int main () {int t; scanf ("%d", &t); while (t--) {memset (a,0,sizeof (a)); scanf ("%d%d", &n,&m); int x, y; for (int i = 1;i <= n;i++)//Initialize pre[i] = i; for (int i = 1;i <= m;i++) {scanf ("%d%d", &x,&y); a[x]++; a[y]++; Join (x, y); } memset (b,0,sizeof (b)); int cont = 0; for (int i = 1;i <= n;i++) {b[find (i)] = 1; Cont + = B[i]; } int sum = 0; for (int i = 1;i <= n;i++)//Determine how many even degrees {if (A[i]% 2 = = 0) sum++; } if (cont = = 1 && (sum = = N | | sum = = n-2)) printf ("yes\n"); else printf ("no\n"); } return 0;}
Nyoj 421 Stroke problem