Kyopro Library
 
読み取り中…
検索中…
一致する文字列を見つけられません
euler_tour.hpp
[詳解]
1#include"../../../kyopro_library/template.hpp"
2
3/// @brief 木 g をオイラーツアーする
4/// @brief `(行きがけ順, 深さ, 入力時刻, 出力時刻)` を返す
5/// @details 部分木のクエリを列のに対する区間クエリとして扱えるようになる
6/// @details 例えば、頂点 v の部分木はオイラーツアー後の列の区間 `[in[v], out[v])` に対応する
7tuple<vector<int>,vector<int>,vector<int>,vector<int>> EulerTour(const vector<vector<int>>& g) {
8 int n=g.size();
9 vector<int> tour,depth(n),in(n),out(n);
10 int time=0;
11 auto dfs=[&](auto&& dfs, int now, int pre, int d)-> void {
12 depth[now]=d;
13 in[now]=time++;
14 tour.push_back(now);
15 for(int nxt:g[now]) if(nxt!=pre) dfs(dfs,nxt,now,d+1);
16 out[now]=time;
17 };
18 dfs(dfs,0,-1,0);
19
20 return {tour,depth,in,out};
21}