HDU 1878 Euro-pull circuit "and check set + Eulerian graph"

Source: Internet
Author: User
Tags printf
Euro-Pull circuit Time limit:2000/1000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 9655 Accepted Submission (s): 3498


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 graph, ask if there is a Euler loop.
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 3 1 2 1 3 2 3 3 2 1 2 2 3 0
Sample Output
1 0/*
The problem of Euler loops based on the Eulerian graph graph is that the condition of a graph is: 0 of all nodes have an odd number of degrees
1. Use and check the set to determine whether a graph
2. Determine if all the nodes are in an even number of degrees
*/
#include <cstdio> #include <cstring> #include <vector> using namespace std; 

int pre[1005],in[1005];
    struct Edge {int from;
int to;
}E[100005];

int find (int x) {return x==pre[x]?x:pre[x]=find (pre[x]);}
    void join (int x,int y) {int fx=find (x), Fy=find (y);
    if (fx!=fy) {pre[fx]=fy;
    }} int main () {int n,m,i,t,flag;
        while (scanf ("%d", &n) &&n) {scanf ("%d", &m);
        int ok=0;
        memset (In,0,sizeof (in));
        memset (E,0,sizeof (e));
        for (I=1; i<=n; i++) pre[i]=i;
            for (I=1; i<=m; i++) {scanf ("%d%d", &e[i].from,&e[i].to);
        in[e[i].from]++,in[e[i].to]++;//statistics into join (E[I].FROM,E[I].TO);
            } for (i=1,t=flag=0; i<=n; i++) {if (in[i]&1) t++;  
        if (pre[i]==i) flag++;
        } if (flag==1&&t==0) ok=1;
        if (OK) printf ("1\n");
    else printf ("0\n"); } return 0; }














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.