Hdoj Euler circuit 1878 "Euler Loop Determination"

Source: Internet
Author: User

Euler circuit Time limit:2000/1000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 10459 Accepted Submission (s): 3815


Problem description is a loop that does not leave the pen on the paper, but only once per side of the picture, and can return to the starting point. Now given a diagram, ask if there is a Euler circuit?
The input test inputs contain several test cases. The 1th line of each test case gives two positive integers, namely the number of nodes N (1 < N < 1000) and the number of sides m, followed by M-bars, each with a pair of positive integers, the number of two nodes (nodes from 1 to N) that are directly connected to the bar. When n is 0 o'clock input knot
Beam.
Output takes one row for each test case, and outputs 1 if the Euler loop is present, otherwise outputs 0.

Sample Input
3 31 21 32 33 21 22 30

Sample Output
10

Authorzju
SOURCE Zhejiang University Computer Postgraduate exam on the machine-2008
Recommendwe carefully selected several similar problems for you:1880 1877 1881 1864 1873

Judging Euler circuits

Whether the ① is a pathway

② All points have an even number of degrees

Determine the access and search for a set

#include <iostream> #include <stdio.h> #include <string.h> #include <algorithm> #include < Vector>using namespace Std;int d[1010];int r[1010];int find_x (int x) {int son=x;int temp;while (x!=r[x]) x=r[x];while ( son!=x) {temp=r[son];r[temp]=x;son=temp;} return x;} int fun (int x,int y) {x=find_x (x); y=find_x (y); if (x!=y) {r[x]=y;}} int main () {int n,m;while (scanf ("%d", &n), N) {scanf ("%d", &m), memset (d,0,sizeof (d)); int a,b;for (int i=0;i<= n;i++) {r[i]=i;} for (int i=0;i<m;i++) {scanf ("%d%d", &a,&b), fun (A, b);d [a]++;d [b]++;} int flag=1;int num=0;for (int i=1;i<=n;i++) {if (r[i]==i) num++;} for (int i=1;i<=n;i++) {if (d[i]&1) {flag=0;break;}} if (flag&&num==1) printf ("1\n"), Else printf ("0\n");}    return 0;}


Copyright NOTICE: This article is the original blogger articles, reproduced please indicate the source.

Hdoj Euler circuit 1878 "Euler Loop Determination"

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.