Graph | Eulerian path

In graph theory, a Eulerian trail (or Eulerian path) is a trail in a graph which visits every edge exactly once. Similarly, an Eulerian circuit or Eulerian cycle is an Eulerian trail which starts and ends on the same vertex.

Hierholzer‘s algorithm 可以在O(E)的时间下给出解。

算法:

  • Choose any starting vertex v, and follow a trail of edges from that vertex until returning to v. It is not possible to get stuck at any vertex other than v, because the even degree of all vertices ensures that, when the trail enters another vertex w there must be an unused edge leaving w. The tour formed in this way is a closed tour, but may not cover all the vertices and edges of the initial graph.
  • As long as there exists a vertex u that belongs to the current tour but that has adjacent edges not part of the tour, start another trail from u, following unused edges until returning to u, and join the tour formed in this way to the previous tour.

当然,需要用到双向链表不断地把边删掉,如果最终所有边都被访问了,那么就可以退出了。但是如果找不到点继续扩展,而且边又还有的话,那么就说明给不出回路。

时间: 2024-10-16 14:03:42

Graph | Eulerian path的相关文章

PAT 1126 Eulerian Path

In graph theory, an Eulerian path is a path in a graph which visits every edge exactly once. Similarly, an Eulerian circuit is an Eulerian path which starts and ends on the same vertex. They were first discussed by Leonhard Euler while solving the fa

PAT 甲级 1126 Eulerian Path

https://pintia.cn/problem-sets/994805342720868352/problems/994805349851185152 In graph theory, an Eulerian path is a path in a graph which visits every edge exactly once. Similarly, an Eulerian circuit is an Eulerian path which starts and ends on the

PAT A1126 Eulerian Path (25 分)

In graph theory, an Eulerian path is a path in a graph which visits every edge exactly once. Similarly, an Eulerian circuit is an Eulerian path which starts and ends on the same vertex. They were first discussed by Leonhard Euler while solving the fa

PAT_A1126#Eulerian Path

Source: PAT A1126 Eulerian Path (25 分) Description: In graph theory, an Eulerian path is a path in a graph which visits every edge exactly once. Similarly, an Eulerian circuit is an Eulerian path which starts and ends on the same vertex. They were fi

1126 Eulerian Path (25 分)

1126 Eulerian Path (25 分) In graph theory, an Eulerian path is a path in a graph which visits every edge exactly once. Similarly, an Eulerian circuit is an Eulerian path which starts and ends on the same vertex. They were first discussed by Leonhard

1126 Eulerian Path

题意:若图是连通图,且所有结点的度均为偶数,则称为Eulerian:若有且仅有两个结点的度为奇数,则称为semi-Eulerian.现给出一个图,要我们判断其是否为Eulerian,semi-Eulerian还是not-Eulerian. 思路:在数据输入的时候计算各个节点的度:在输出各个节点的度的同时记录度为奇数的结点个数:最后判断判断图是否连通.这种题不考察什么算法,关键要我们理解题意,往往都是很简单的! 代码: #include <cstdio> #include <cstring

《算法》第四章部分程序 part 7

? 书中第四章部分程序,包括在加上自己补充的代码,图中找欧拉环 ● 无向图中寻找欧拉环 1 package package01; 2 3 import edu.princeton.cs.algs4.StdOut; 4 import edu.princeton.cs.algs4.StdRandom; 5 import edu.princeton.cs.algs4.GraphGenerator; 6 import edu.princeton.cs.algs4.Graph; 7 import edu.

【432】COMP9024,Exercise9

eulerianCycle.c What determines whether a graph is Eulerian or not? Write a C program that reads a graph, prints the graph, and determines whether an input graph is Eulerian or not. if the graph is Eulerian, the program prints an Eulerian path you sh

Java数据结构——带权图

带权图的最小生成树——Prim算法和Kruskal算法 带权图的最短路径算法——Dijkstra算法 package graph; // path.java // demonstrates shortest path with weighted, directed graphs 带权图的最短路径算法 // to run this program: C>java PathApp ////////////////////////////////////////////////////////////