- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheuler_tour.cpp
More file actions
Latest commit
27 lines (21 loc) · 566 Bytes
/
Copy patheuler_tour.cpp
File metadata and controls
27 lines (21 loc) · 566 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#include<iostream>
#include<vector>
usingnamespacestd;
constintMAX = 100005;
vector<int> adj[MAX];
int in_time[MAX], out_time[MAX];
int timer;
voiddfs_euler(int cur, int p) {
in_time[cur] = ++timer;
for (int next : adj[cur]) {
if (next != p) {
dfs_euler(next, cur);
}
}
out_time[cur] = timer;
}
// 쿼리: u가 v의 조상인가? (in[u] <= in[v] && out[v] <= out[u])
boolis_ancestor(int u, int v) {
return in_time[u] <= in_time[v] && out_time[v] <= out_time[u];
}
// 서브트리 쿼리: [in[u], out[u]] 구간 쿼리로 변환