a stroke problemtime limit:ms | Memory limit:65535 KB 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
Train of thought: 1, Judge Unicom, use DFS or check set all line
2, the number of odd points is 0 or the number of odd points is 2, you can a pen, or you need to COUNT/2 pen
Code:
#include <iostream>
#include <cstring>
#include <vector>
#include <cstdio>
using namespace std;
vector<int>mp[1005];
int vis[1005];
int num;
void Dfs (int x)
{
vis[x]=1;
num++;
for (int i=0;i<mp[x].size (); i++)
{
int v=mp[x][i];
if (!vis[v])
Dfs (v);
}
}
int main ()
{int n,m,k;
cin>>n;
While (n--)
{
cin>>m>>k;
for (int i=0;i<=m;i++)
if (mp[i].size ())
mp[i].clear ();
int A, b;
for (int i=0;i<k;i++)
{
scanf ("%d%d", &a,&b);
Mp[a].push_back (b);
Mp[b].push_back (a);
}
num=0;
int t=0;
for (int i=1;i<=m;i++)
if (mp[i].size ()%2)
t++;
memset (vis,0,sizeof (Vis));
Dfs (b);
if (num==m&& (t==0| | t==2))
cout<< "Yes" <<endl;
Else
cout<< "No" <<endl;
}
return 0;
}
nyoj-a stroke problem-Eulerian graph + unicom decision