歐拉回路和歐拉路徑求法 dfs遞歸模板

#include<cstdio>
#include<cstring>
#include<iostream>
#include<iomanip>
#include<queue>
#include<cmath>
#include<stack>
#include<map>
#include<vector>
#include<set>
#include<algorithm>
using namespace std;
typedef long long LL;
const int int_max = 0x07777777;
const int int_min = 0x80000000;
int smaller (int a, int b) { return (a > b ? b : a); }
int bigger (int a, int b) { return (a > b ? a : b); }
const int maxn = 100;
struct Edge {
    int from,to;
    Edge(int _from, int _to):from(_from),to(_to){}
};
vector<Edge> es;
vector<int> g[maxn];
int vis[1100];
int tot;
void addedge (int from, int to){
    es.push_back(Edge(from, to));
    g[from].push_back(es.size()-1);
}
void dfs(int x, int pre){
    for(int i = 0; i < g[x].size(); i++){
        if(!vis[g[x][i]]){
            vis[g[x][i]] = 1;
            dfs(es[g[x][i]].to, g[x][i]);
        }
    }
    if(pre!=-1) root[tot++] = pre;
}
void solve (){
		tot = 0;
		memset(vis,0,sizeof(vis));
		dfs(src,-1)
}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章