Sdut 3364 Data structure Experiment diagram theory eight: Euler circuit

Source: Internet
Author: User

Diagram of data structure experiment eight: Euler circuitTime limit:1000ms Memory limit:65536kb SubmitStatisticProblem Description

In a park in Fort Königsberg, there are seven bridges linking the two islands and islands of the Pregel River to the river banks.



Can you walk through such seven bridges and walk only once per bridge? The Swiss mathematician Euler finally solved the problem and created the topology. Euler's study of the seven bridge problem not only satisfactorily answered the seven-bridge problem of Fort Königsberg, but also proved a wider range of three conclusions about a stroke, commonly called Euler's theorem. For a connected graph, the route that is drawn from a node is usually called the Euler road. The Euler's path, which is often used as a return to the starting point, is called the Euro-pull circuit. A graph with a Euler loop is called Eulerian graph.

Your task is to determine if a given set of graph data is Eulerian graph?

Input continuous T-Group data entry, the first row of each group of data gives two positive integers, representing the number of nodes N (1 < N <= 1000) and the number of sides m, then the M line corresponds to M-bar, each row gives two positive integers, representing the number of two nodes connected by the edge, and the nodes from the 1~n number. Output 1 If output is Eulerian graph, otherwise 0. Example Input
16 101 22 33 14 55 66 41 41 63 43 6
Example Output
1
Hint if the undirected graph is connected and the degree of all nodes is even, there is a Euler loop, otherwise it does not exist. DQE:The subject is very simple do not want to complicate, pay attention to the problem hint to determine the conditions, the implementation of a depth first search can be resolved, I wish everyone smooth ac~
1#include <iostream>2#include <cstdio>3 4 using namespacestd;5 6 #defineMVN 10107 8typedefstructAdjmatrix9 {Ten     intW; One     Char*info; A }am; -  -typedefstructMgraph the { -     intVEX[MVN]; - AM ARC[MVN][MVN]; -     intVexnum,arcnum; + }mg; -  + voidCreat (MG &G) A { at     inti,j,k; -      for(k=1; k<=g.vexnum;k++) -g.vex[k]=K; -      for(k=1; k<=g.arcnum;k++) -     { -scanf"%d%d",&i,&j); ing.arc[i][0].w++; -g.arc[j][0].w++; tog.arc[i][j].w=1; +g.arc[j][i].w=1; -     } the } *  $ intcount;Panax Notoginseng voidDFS (MG G,BOOL*visited,inti) - { thevisited[i]=true; +count++; A     intK; the      for(k=1; k<=g.vexnum;k++) +     { -         if(g.arc[i][k].w>0&&visited[k]==false) $ DFS (g,visited,k); $     } - } -  the intMain () - {Wuyi     intT; thescanf"%d",&t); -      while(t--) Wu     { -MG g={0}; Aboutscanf"%d%d",&g.vexnum,&g.arcnum); $ creat (G); -         intk,f=0; -          for(k=1; k<=g.vexnum;k++) -         { A             if(g.arc[k][0].w%2!=0) +             { thef=1; -                  Break; $             } the         } the         if(f) the         { theprintf"0\n"); -             Continue; in         } theCount=0; the         BOOLvisited[mvn]={false}; AboutDFS (g,visited,1); the         if(count!=g.vexnum) the         { theprintf"0\n"); +             Continue; -         } theprintf"1\n");Bayi     } the     return 0; the } -  - /*************************************************** the User Name: * * * the result:accepted the Take time:56ms the Take memory:11588kb - Submit time:2016-11-09 21:56:24 the ****************************************************/

Sdut 3364 Data structure Experiment diagram theory eight: Euler circuit

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.