Euler circuit base HDU1878 Euler circuit | | and the difference set

Source: Internet
Author: User


Welcome to the Bestcoder-every Saturday night (with rice!) )
Euler circuit

Time limit:2000/1000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 10544 Accepted Submission (s): 3845


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 INPUT3 31 21 32 33 21 22 30

Sample Output10

Authorzju

Source Zhejiang University Computer Postgraduate exam on the machine-2008

Recommendwe has carefully selected several similar problems for you:1877 1881 1863 1875 1864 attached: PS naked Euler circuit, below two No The gaze was written by me, without gaze, as a template, with a gaze on the web, easy to understand thanks to the great God
#include <stdio.h>#include<string.h>#include<iostream>#include<algorithm>using namespacestd;Const intmaxn=1005;intMAP[MAXN][MAXN];BOOLVIS[MAXN];intINDEGREE[MAXN];intn,m;voidDfsintu) {Vis[u]=true;  for(intI=1; i<=n;i++)    if(!vis[i]&&Map[u][i]) DFS (i); return ;}intMain () { while(SCANF ("%d", &n) &&N) {scanf ("%d",&m); memset (Map,0,sizeof(map)); memset (Vis,false,sizeof(VIS)); memset (Indegree,0,sizeof(Indegree));  for(intI=0; i<m;i++){            intu,v; scanf ("%d%d",&u,&v); Indegree[u]++; INDEGREE[V]++; MAP[U][V]=map[v][u]=1; } DFS (1); inti;  for(i=1; i<=n;i++){            if(!vis[i]| | indegree[i]%2==1)                 Break; }        if(i>N) printf ("1\n"); Elseprintf ("0\n"); }    return 0;}
//This paper mainly examines the two necessary and sufficient conditions of the Euler circuit: 1. Unicom Figure 2. Vertex degrees are even (two conditions are indispensable)#include<stdio.h>#include<string.h>intgraph[ +][ +];//using adjacency matrix to store graphsintvisit[ +];//Mark whether the point has been accessed over the durationintdegree[ +];//the degree of storage nodevoidDFS (intVintN) {//Depth-first traversal, recursiveVISIT[V] =1;  for(intI=1; i<=n; i++)        if(Graph[v][i] && visit[i]==0) DFS (i,n);}intMain () {//freopen ("In.txt", "R", stdin);    intN, M;  while(SCANF ("%d%d", &n,&m)!=eof &&N) {memset (graph,0,sizeof(graph));//Qing 0memset (Visit,0,sizeof(visit)); memset (degree,0,sizeof(degree)); intA, B, I; intFlag =1;//Mark if there is a Euler loop         for(i=0; i<m; i++) {scanf ("%d%d",&a,&b); GRAPH[A][B]= Graph[b][a] =1;//"1" indicates that two points belong to the adjacency relationshipdegree[a]++; degree[b]++; } DFS (1, N);  for(i=1; i<=n; i++) {            if(Visit[i] = =0) {flag=0;//If a bit has not been accessed, that is, a deep traversal with an unreachable point, there is no Euler loop                 Break; }            if(Degree[i]%2!=0) {flag=0;//if the degree is not even, then the Euler circuit does not exist.                 Break; }        }        if(flag) printf ("1\n"); Elseprintf ("0\n"); }    return 0;}

Euler circuit base HDU1878 Euler circuit | | and the difference set

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.