Euler diagram, semi-Euler diagram

Definitions of Eulerian and semi-Eulerian graphs:

Euler Circuit: The circuit passing through each edge once and only once in graph G is called Euler Circuit.

Euler Path: The path that passes through each edge once and only once in Figure G is called Euler Path.

 

that

Eulerian graph refers to a graph with Eulerian loops.

Semi-Eulerian graph refers to a graph with Eulerian path but no Eulerian loop.

 

The conditions for their existence are as follows:

1. In undirected graphs:

The undirected graph G is an Eulerian graph if and only if G is a connected graph and the degree of all vertices is even.
  
The undirected graph G is a semi-Eulerian graph if and only if G is a connected graph and the degrees of all vertices are even except for the odd degrees of two vertices.

2. digraph:

The directed graph G is an Euler graph, if and only if G is a connected graph, and the vertices of all vertices are equal to degree of output.
  
The digraph G is a semi Eulerian graph. If and only if G is a connected graph, and the degree of penetration of the vertex u is larger than the degree of degree 1, the degree of penetration of v is smaller than the degree of degree of 1, and the penetration of all the other vertices is equal to the degree of output.

 

Title: Input a graph, output can find a path through all the edges without repeating

#include <iostream>
#include <vector>
#include <cstdio>
using namespace std;

int qiVertex = 0, ouVertex = 0;
int cnt = 0;

void EulerDfs(int start, int vertex, int edge, vector<vector<int>> origin, vector<bool>& vis) {
    vis[start] = true;
    cnt++;
    for (int i = 1; i <= vertex; ++i) {
        if(origin[start][i] == 1 && vis[i] == false){
            EulerDfs(i,vertex,edge, origin, vis);
        }
    }
}

int main(){
    int n, m; //Number of edges
    int flag = false;
    scanf("%d %d", &n, &m);
    vector<vector<int>> G(n+1,vector<int>(n+1,0));
    vector<int> degree(n+1,0);
    vector<bool> vis(n+1, false);
    vector<bool> viss(n+1, false);
    for (int i = 0; i < m; ++i) {
        int u,v;
        scanf("%d %d", &u, &v);
        degree[u]++;
        degree[v]++;
        G[u][v] = 1;
        G[v][u] = 1;
    }
    for (int k = 1; k <= n; ++k) {
        if(degree[k]&1 == 1){
            qiVertex++;
        }
    }
    if(qiVertex == 2){
        for (int j = 1; j <= n; ++j){
            vis = viss;
            EulerDfs(j,n,m, G, vis);
            if(cnt == n) flag = true;
        }
    }
    if(flag) printf("Yes\n");
    else printf("No\n");

    return 0;
}

 

Posted by funguse on Sun, 06 Oct 2019 08:58:34 -0700