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 "treinc.h"
using namespace std;
int acum,niv[400005];
void init()
{
acum=2;
niv[1]=1;
}
int tata[20][400005];
int lg=19,inainte,j;
void path (int a,int s)
{
inainte=a;
int i;
for (i=acum; i<=acum+s-1; i++)
{
niv[i]=niv[inainte]+1;
tata[0][i]=inainte;
inainte=i;
}
for (j=1; j<=19; j++)
{
for (i=acum; i<=acum+s-1; i++)
{
tata[j][i]=tata[j-1][tata[j-1][i]];
}
}
acum=acum+s;
}
int tatic(int x,int dist)
{
int acum,i;
acum=x;
for (i=0; i<=19; i++)
{
if ((dist&(1<<i)))
{
acum=tata[i][acum];
}
}
return acum;
}
int lca(int x,int y)
{
if (niv[x]<niv[y])
{
return lca(y,x);
}
int dif=niv[x]-niv[y];
x=tatic(x,dif);
if (x!=y)
{
for (int i=19; i>=0; i--)
{
if (tata[i][x]!=tata[i][y])
{
x=tata[i][x];
y=tata[i][y];
}
}
x=tata[0][x];
}
return x;
}
int dig(int x,int y)
{
int salut=lca(x,y);
int stanga=niv[x]-niv[salut],dreapta=niv[y]-niv[salut];
int dist=(stanga+dreapta)/2;
if (dist<=stanga)
{
return tatic(x,dist);
}
else
{
dreapta=dreapta-(dist-stanga);
return tatic(y,dreapta);
}
}
# | 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... |
# | 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... |