# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
349763 | pavement | 경주 (Race) (IOI11_race) | C++17 | 0 ms | 0 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "race.h"
#include <bits/stdc++.h>
using namespace std;
int _K, ans = 1e9, dist[1000005], dep[1000005];
vector<pair<int, int> > adj[1000005];
set<pair<int, int> > S[1000005];
void dfs(int n, int e = -1) {
S[n].emplace(dist[n], dep[n]);
for (auto u : adj[n]) {
if (u.first != e) {
dist[u.first] = dist[n] + u.second;
dep[u.first] = dep[n] + 1;
dfs(u.first, n);
if (S[n].size() < S[u.first].size()) swap(S[n], S[u.first]);
for (auto i : S[u.first]) {
auto it = S[n].lower_bound(make_pair(_K - i.first + 2 * dist[n], 0));
if (it != S[n].end() && it->first + i.first - 2 * dist[n] == K) ans = min(ans, it->second + i.second - 2 * dep[n]);
}
for (auto i : S[u.first]) S[n].insert(i);
}
}
}