Nyoj42 a stroke problem (Euler loop)

Source: Internet
Author: User

    • topic information
    • run result
    • line
    • discussion area
Time limit for a stroke problem: theMs | Memory Limit:65535KB Difficulty:4

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.

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.
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
[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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.