1 介绍
本专题用来记录欧拉回路和欧拉路径相关的题目。
相关结论:
(1)对于无向图,所有边都是连通的。
(1.1)存在欧拉路径的充要条件:度数为奇数的结点只能是0个或者2个。
(1.2)存在欧拉回路的充要条件:度数为奇数的结点只能是0个。
(2)对于有向图,所有边都是连通的。
(2.1)存在欧拉路径的充要条件1:所有结点的出度均等于其入度。
(2.1)存在欧拉路径的充要条件2:除去两个结点外,其余所有结点的出度等于入度。且除去的那两个结点,其中一个结点的出度比入度多1(起点),另一个结点的入度比出度多1(终点)。
(2.2)存在欧拉回路的充要条件:所有结点的出度均等于其入度。
2 训练
题目1:1123铲雪车
C++代码如下,
#include <cstring>
#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;
int main() {
double x1, y1, x2, y2;
cin >> x1 >> y1;
double sum = 0;
while (cin >> x1 >> y1 >> x2 >> y2) {
double dx = x1 - x2;
double dy = y1 - y2;
sum += sqrt(dx * dx + dy * dy) * 2;
}
int minutes = round(sum / 1000 / 20 * 60);
int hours = minutes / 60;
minutes %= 60;
printf("%d:%02d\n", hours, minutes);
return 0;
}
题目2:1184欧拉回路
C++代码如下,
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
const int N = 100010, M = 400010;
int type;
int n, m;
int h[N], e[M], ne[M], idx;
bool used[M];
int ans[M], cnt;
int din[N], dout[N];
void add(int a, int b) {
e[idx] = b, ne[idx] = h[a], h[a] = idx++;
}
void dfs(int u) {
for (int &i = h