Skip to content

Instantly share code, notes, and snippets.

@joonas-yoon
Created May 13, 2020 10:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joonas-yoon/2c3b5c01d63baedd25baf40a8f58402a to your computer and use it in GitHub Desktop.
Save joonas-yoon/2c3b5c01d63baedd25baf40a8f58402a to your computer and use it in GitHub Desktop.
using Eulerian path
#define MAX_V 100001
int id = 0;
int L[MAX_V], R[MAX_V]; // [L, R]
vector<int> adj[MAX_V];
int dfs(int cur) {
int i = ++id, cnt = 0;
L[cur] = i;
for (auto& nxt : adj[cur]) {
cnt += 1 + dfs(nxt);
}
R[cur] = i + cnt;
return cnt;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment