# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
276060 | abyyskit | 경주 (Race) (IOI11_race) | C++14 | 3024 ms | 30548 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "race.h"
#include<bits/stdc++.h>
using namespace std;
#define FOR(i, x, y) for(int i = x; i < y; ++i)
#define pb push_back
int ANS;
int TIME;
int K;
struct node{
vector<int> e;
vector<long long> w;
int start = -1;
int end;
vector<int> l = vector<int>(19);
long long p = 0;
int h;
};
vector<node> g;
void dfs(int start, int height){
g[start].start = TIME;
g[start].h = height;
TIME++;
FOR(i, 0, g[start].e.size()){
int nex = g[start].e[i];
if (g[nex].start == -1){
g[nex].l[0] = start;
g[nex].p = g[start].p + g[start].w[i];
dfs(nex, height + 1);
}
}
g[start].end = TIME;
TIME++;
}
void setup_LCA(){
g[0].l[0] = 0;
FOR(i, 0, g.size()){
FOR(j, 1, g[i].l.size()){
g[i].l[j] = g[g[i].l[j - 1]].l[j - 1];
}
}
}
int LCA(int a, int b){
int cur = a;
//cout << a << " " << b << "\n";
for (int i = g[a].l.size() - 1; i >= 0; --i){
int nex = g[cur].l[i];
if (!(g[nex].start <= g[b].start and g[b].start <= g[nex].end)){
cur = nex;
}
// cout << " step: " << i << " looked at " << nex << " now at " << cur << "\n";
}
int tmp = 0;
// cout << " " << g[cur].start << " " << g[b].start << " " << g[cur].end << "\n";
while (!(g[cur].start <= g[b].start and g[b].start <= g[cur].end)){
cur = g[cur].l[0];
// cout << " here\n";
tmp++;
if (tmp > 2){
// cout << "suicide\n";
// cout << (1/0) << "\n";
}
}
// cout << "LCA(" << a << ", " << b << ") = " << cur << ", ";
return cur;
}
int solve(int a, int b){
int c = LCA(a, b);
int dis = g[a].h + g[b].h - 2*g[c].h;
long long odis = g[a].p + g[b].p - 2*g[c].p;
// cout << "dis(" << a << ", " << b << ") = " << dis << ", ";
// cout << "odis(" << a << ", " << b << ") = " << odis << ", ";
// cout << "\n";
if (odis == K){
return dis;
}
else{
return g.size() + 1;
}
}
int best_path(int N, int k, int H[][2], int L[]){
ANS = N + 1;
K = k;
TIME = 0;
g.resize(N);
FOR(i, 0, N-1){
g[H[i][0]].e.pb(H[i][1]);
g[H[i][0]].w.pb(L[i]);
g[H[i][1]].e.pb(H[i][2]);
g[H[i][1]].w.pb(L[i]);
}
dfs(0, 0);
setup_LCA();
FOR(i, 0, N){
FOR(j, i + 1, N){
ANS = min(ANS, solve(i, j));
}
}
if (ANS == N + 1){
ANS = -1;
}
return ANS;
}
컴파일 시 표준 에러 (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... |