# | TimeUTC-0 | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1160032 | Hamed_Ghaffari | Railway (BOI17_railway) | C++20 | 38 ms | 23996 KiB |
#include<bits/stdc++.h>
using namespace std;
using pii = pair<int, int>;
#define pb push_back
#define all(x) x.begin(), x.end()
const int MXN = 1e5+5;
const int LOG = 17;
int n, par[LOG][MXN], stt[MXN], fnt[MXN], timer;
vector<pii> g[MXN];
void dfs(int v) {
for(int i=1; i<LOG; i++)
par[i][v] = par[i-1][par[i-1][v]];
stt[v] = timer++;
for(auto [u, i] : g[v])
if(u!=par[0][v])
par[0][u]=v,
dfs(u);
fnt[v] = timer;
}
bool is_anc(int u, int v) { return stt[u]<=stt[v] && fnt[v]<=fnt[u]; };
int LCA(int u, int v) {
if(is_anc(u, v)) return u;
for(int i=LOG-1; i>=0; i--)
if(par[i][u] && !is_anc(par[i][u], v))
u = par[i][u];
# | 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... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |