# | TimeUTC-0 | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
543865 | AJ00 | Race (IOI11_race) | C++14 | 0 ms | 0 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>
//#include "race.h"
using namespace std;
//#define ll long long
#define ll long long
const ll MAXN = 200001;
const ll LOGN = 20;
vector<vector<pair<ll,ll>>> adj(MAXN);
int depth[MAXN];
ll par[MAXN][LOGN],weight[MAXN][LOGN];
pair<ll,int> lca(ll x, ll y){
ll X = x, Y = y;
if (depth[X] < depth[Y]){
swap(x,y);
swap(X,Y);
}
ll dh = depth[x]-depth[y];
ll totw = 0;
for (ll i = LOGN-1; i >= 0; i--){
if (dh&(1<<i)){
totw += weight[x][i];
x = par[x][i];
}
}
if (x == y){
return {totw, depth[X]-depth[Y]};
}
int lvl = 0;
for (ll i = LOGN; i >= 0; i--){
if (par[x][i] != par[y][i]){