欧拉回路/路径求法

本文搬运自本人高中时期CSDN博客,若图片加载不出来,可到原文查看:https://blog.csdn.net/zhangtingxiqwq/article/details/132082624

以任意一点/奇数度点开始dfs,能走就走,遍历所有边,离开时加入点。

1
2
3
4
5
6
7
void dfs(int x) {
for(; t[x]<G[x].size(); ) {
int y=G[x][t[x]]; ++t[x];
dfs(y);
}
z.push(x);
}