# | TimeUTC-0 | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
201015 | dolphingarlic | Putovanje (COCI20_putovanje) | C++14 | 203 ms | 28652 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.
#include <bits/stdc++.h>
#define FOR(i, x, y) for (int i = x; i < y; i++)
typedef long long ll;
using namespace std;
int n;
vector<int> graph[200001];
ll bit[200001];
int tin[200001], tout[200001], timer = 0;
int anc[200001][20];
void dfs(int node = 1, int parent = 0) {
anc[node][0] = parent;
FOR(i, 1, 20) anc[node][i] = anc[anc[node][i - 1]][i - 1];
tin[node] = ++timer;
for (int i : graph[node]) if (i != parent) dfs(i, node);
tout[node] = timer;
}
bool is_ancestor(int a, int b) { return tin[a] <= tin[b] && tout[a] >= tout[b]; }
int lca(int a, int b) {
if (is_ancestor(a, b)) return a;
for (int i = 19; ~i; i--) {
if (anc[a][i] && !is_ancestor(anc[a][i], b)) a = anc[a][i];
}
return anc[a][0];
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |