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
AC Code
#include <stdio.h> #include <string.h>int head[1010];struct s{int u,v,next;} Edge[2020*2];int n,m,cnt,vis[1010],dig[1010],sum;void Add (int u,int v) {edge[cnt].u=u;edge[cnt].v=v;edge[cnt].next= head[u];head[u]=cnt++;} void Dfs (int u) {vis[u]=1;sum++;for (int i=head[u];i!=-1;i=edge[i].next) {int v=edge[i].v;if (!vis[v]) Dfs (v);}} int main () {int t;scanf ("%d", &t), while (t--) {//int n,m;scanf ("%d%d", &n,&m); int I,cnt=0;memset (Head,-1, sizeof (head)), memset (vis,0,sizeof (Vis)), memset (dig,0,sizeof (Dig)), for (i=0;i<m;i++) {int u,v;scanf ("%d%d", &U,&V);d ig[u]++;d ig[v]++;add (u,v); add (v,u);} Sum=0;dfs (1); if (sum<n) {printf ("no\n"); continue;} int Ans=0;for (i=1;i<=n;i++) {if (dig[i]&1) ans++;} if (ans==2| | ans==0) {printf ("yes\n");} elseprintf ("no\n");}}
Nyoj Topic 421 Stroke problem (Eulerian graph)