# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
948250 | Lib | Race (IOI11_race) | C++14 | 1 ms | 6492 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;
vector <vector <pair <int,int> > > adj;
vector <pair <int,int> > TVector;
int SubtreeSize[300003];
int CurParent[300003];
int IteratedAdj[300003];
int Deleted[300003];
int Visited[300003];
int DistFromRoot[300003];
long long ans=999999;
int N,Tar;
int cur;
void DFS(){
vector <int> DFStack;
for(int i=0;i<=N;i++){
CurParent[i]=-1;
IteratedAdj[i]=0;
SubtreeSize[i]=1;
DistFromRoot[i]=0;
}
for(int i=0;i<N;i++){
if(!Deleted[i]&&!Visited[i]){
DFStack.push_back(i);
Visited[i]=1;
while(!DFStack.empty()){
cur=DFStack.back();
Visited[cur]=1;
if(adj[cur][IteratedAdj[cur]].first==CurParent[cur]){
IteratedAdj[cur]++;
}
if(IteratedAdj[cur]<adj[cur].size()-1){ //still has children
DFStack.push_back(adj[cur][IteratedAdj[cur]].first);
CurParent[adj[cur][IteratedAdj[cur]].first]=cur;
DistFromRoot[adj[cur][IteratedAdj[cur]].first]=DistFromRoot[cur]+adj[cur][IteratedAdj[cur]].second;
IteratedAdj[cur]++;
}else{ //no more children. Remove from DFStack
SubtreeSize[CurParent[cur]]+=SubtreeSize[cur];
DFStack.pop_back();
}
}
}
}
}
void Solve(){
}
int best_path(int n, int k, int H[][2], int L[]){
N=n;
Tar=k;
for(int i=0;i<=N+1;i++){
adj.push_back(TVector);
}
for(int i=1;i<=N-1;i++){
adj[H[i-1][0]].push_back({H[i-1][1],L[i-1]});
adj[H[i-1][1]].push_back({H[i-1][0],L[i-1]});
}
for(int i=0;i<=N;i++){
Deleted[i]=0;
}
Solve;
if(ans==999999){
return -1;
}else{
return ans;
}
}
Compilation message (stderr)
# | 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... |