SCU 4520 Euler-Euler circuit

Source: Internet
Author: User
Tags in degrees

EulerTime limit:0MS Memory Limit:0KB 64bit IO Format:%lld &%llu

Description

Time limit:1000 MS Memory limit:256 M

A graph of n points and m edges is given, and it is judged whether there is a Oraton path under the condition of both the graph and the direction graph.

Input

The input contains multiple sets of data. The first behavior is an integer t (1?≤? T?≤?100), representing the number of data groups, for each group of data: The first row is two integers n and m ( 1?≤? n? ≤?500,?0?≤? m≤? N (n? −?1)/2), respectively, representing the number of points on the graph and the number of edges.
Then the M line, two integers per line, ui and vi ( 1?≤? Ui,? v i? ≤? n,? u i? ≠? v i ), which represents the two points connected by an edge on the diagram. The input guarantees no heavy edges.

Output

First Judge: If this picture is a non-direction diagram, whether there is Euler pathway;
Second judgment: If this picture is a graph, whether there is Oraton road.
For each judgment, if present, output "Yes", otherwise output "no" (not including quotation marks). Two judgments are separated by a space.

Sample input

3

2 1
1 2

4 3
1 2
1 3
1 4

4 4
1 2
1 3
1 4
2 3

Sample output

Yes Yes
No no
Yes No

Hint

Euler's access, Eulerian graph circuit,
no-show diagram :
1) Set G is a connected undirected graph, it is said that through the g of each edge once and only once the path is Euler path;
2) If the Oraton road is a loop (the starting and ending points are the same vertex), then this loop is called the Euler circuit (circuit);
3) The non-direction graph G with a Euler loop is called Eulerian graph (Euler graph).
to map :
1) Set D is the direction graph, the base diagram of D is connected, it is said that each edge of D is once and only once of the direction of the direction of the Euler path;
2) If there is a forward loop to the Oraton road, it is said that there is a forward loop to the Euler circuit (directed Euler circuit);
3) A direction diagram D with a forward Euler loop is called a Eulerian graph (directed Euler graph).

Extend

Euler loop print path algorithm: Fleury (Flore) algorithm

Author

Goozy

It can be done in degrees.

#include <iostream> #include <cstring> #include <cstdio> #include <algorithm> #include < queue> #include <vector> #include <iomanip> #include <math.h> #include <map>using namespace STD; #define FIN freopen ("Input.txt", "R", stdin), #define FOUT freopen ("Output.txt", "w", stdout); #define INF 0x3f3f 3f3f#define Lson l,m,rt<<1#define Rson m+1,r,rt<<1|1typedef long long ll;const int MAXN=1000+5;int DU[MA   Xn];int in[maxn],out[maxn];int n,m,sz;int father[maxn];void edge_init () {memset (du,0,sizeof (DU));   memset (In,0,sizeof (in));   Memset (out,0,sizeof (out));   for (int i=1;i<=n;i++) {father[i]=i;    }}int Find (int x) {if (x!=father[x]) {father[x]=find (father[x]); } return father[x];}    int main () {//fin int T;    scanf ("%d", &t);        while (t--) {scanf ("%d%d", &n,&m);        Edge_init ();        int sum=n;            for (int i=1;i<=m;i++) {int u,v; scanf ("%d%d", &AMP;U,&AMP;V);            du[u]++;            du[v]++;            in[v]++;            out[u]++;            int root1=find (u);            int Root2=find (v);                if (Root1!=root2) {father[root2]=root1;            sum--;            }} if (Sum!=1) {printf ("No no\n");        Continue        } int cnt=0;        for (int i=1;i<=n;i++) {if (du[i]%2==1) cnt++; } if (cnt==0| |        cnt==2) printf ("Yes");        else printf ("No");            BOOL Flag=1;            int fir=0, sec=0;                    for (int i=1;i<=n;i++) {if (In[i]!=out[i]) {if (!fir&&in[i]-out[i]==1) fir=1;                    else if (!sec&&in[i]-out[i]==-1) {sec=1;                    }else{flag=0;            }}} if (flag) printf ("yes\n");    else printf ("no\n"); } return 0;}

  

SCU 4520 Euler-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.