Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // O(E + V )
- unordered_map<int,vector<int>> adj; // graph represented as an adjacency list
- int n; // number of vertices
- vector<int> color;
- vector<int> time_in, time_out;
- int dfs_timer = 0;
- void dfs(int v) {
- time_in[v] = dfs_timer++;
- color[v] = 1;
- for (int u : adj[v])
- if (color[u] == 0)
- dfs(u);
- color[v] = 2;
- time_out[v] = dfs_timer++;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement