# | TimeUTC-0 | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
42294 | minhtung0404 | Birthday gift (IZhO18_treearray) | C++14 | 1549 ms | 113576 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
//https://oj.uz/problem/view/IZhO18_treearray
#include<bits/stdc++.h>
const int N = 2e5 + 5;
using namespace std;
vector <int> adj[N];
set <int> ans[2][N];
int n, m, q, a[N], p[N][20], d[N];
void dfs(int u){
for (int i = 0; i < (int)adj[u].size(); i++){
int v = adj[u][i];
if (v == p[u][0]) continue;
d[v] = d[u] + 1; p[v][0] = u;
dfs(v);
}
}
int lca(int u, int v){
if (d[u] < d[v]) swap(u, v);
for (int i = 19; i >= 0; i--) if (d[u] - (1 << i) >= d[v]) u = p[u][i];
for (int i = 19; i >= 0; i--) if (p[u][i] != p[v][i]) u = p[u][i], v = p[v][i];
return ((u != v) ? p[u][0] : u);
}
int main(){
ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
cin >> n >> m >> q;
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |