我的数据结构与算法题目集代码仓:https://github.com/617076674/Data-structure-and-algorithm-topic-set
原题链接:https://pintia.cn/problem-sets/15/problems/859
题目描述:
知识点:图的深度优先遍历、欧拉回路
思路:和PAT-ADVANCED1126——Eulerian Path同样的解法
解题之前需要提前知道欧拉回路的判断条件:
如果无向图连通并且所有节点的度数都是偶数,则回路存在;否则不存在。
C++代码:
#include<iostream>
#include<vector>
using namespace std;
struct node{
int v;
};
int N, M;
vector<int> graph[1001];
bool visited[1001];
int degree[1001];
void dfs(int nowVisit);