Kuro-orzz's Library

This documentation is automatically generated by online-judge-tools/verification-helper

View on GitHub

:heavy_check_mark: Tree/EulerTour/EulerTour.h

Depends on

Verified with

Code

#include "../../template.h"

vector<int> EulerTour(vector<int> &st, vector<int> &en, 
                vector<vector<int>> &adj, int root = 0, int type = 0) {
    int n = adj.size();
    st.assign(n, 0);
    en.assign(n, 0);
    vector<int> tour;
    if (type == 0) tour.reserve(n);
    else if (type == 1) tour.reserve(2 * n);
    int pos = 0;
    function<void(int, int)> dfs = [&] (int u, int par) {
        tour.push_back(u);
        st[u] = ++pos;
        for (int v : adj[u]) {
            if (v == par) continue;
            dfs(v, u);
        }
        if (type == 1) {
            tour.push_back(u);
            pos++;
        }
        en[u] = pos;
    };
    dfs(root, -1);
    return tour;
}
#line 2 "template.h"

#include <bits/stdc++.h>
using namespace std;
 
#define ll long long
#define MOD (ll)(1e9+7)
#define all(x) (x).begin(),(x).end()
#define unique(x) x.erase(unique(all(x)), x.end())
#define INF32 ((1ull<<31)-1)
#define INF64 ((1ull<<63)-1)
#define inf (ll)1e18

#define vi vector<int>
#define pii pair<int, int>
#define pll pair<ll, ll>
#define fi first
#define se second

const int mod = 998244353;

void solve();

int main(){
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    // cin.exceptions(cin.failbit);
    // int t; cin >> t;
    // while(t--)
        solve();
    cerr << "\nTime run: " << 1000 * clock() / CLOCKS_PER_SEC << "ms" << '\n';
    return 0;
}
#line 2 "Tree/EulerTour/EulerTour.h"

vector<int> EulerTour(vector<int> &st, vector<int> &en, 
                vector<vector<int>> &adj, int root = 0, int type = 0) {
    int n = adj.size();
    st.assign(n, 0);
    en.assign(n, 0);
    vector<int> tour;
    if (type == 0) tour.reserve(n);
    else if (type == 1) tour.reserve(2 * n);
    int pos = 0;
    function<void(int, int)> dfs = [&] (int u, int par) {
        tour.push_back(u);
        st[u] = ++pos;
        for (int v : adj[u]) {
            if (v == par) continue;
            dfs(v, u);
        }
        if (type == 1) {
            tour.push_back(u);
            pos++;
        }
        en[u] = pos;
    };
    dfs(root, -1);
    return tour;
}
Back to top page