이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "race.h"
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<ll, ll>;
const int MxN = 2e5 + 5, MxK = 1e6 + 5;
ll d, sz[MxN], rpar, mn[MxK], ans = 1e12;
vector<pii> v[MxN], u[MxN];
vector<ll> t;
bool f[MxN];
ll dfssz (ll cur, ll par) {
sz[cur] = 1;
for (auto &[x, y]: v[cur]) if (par != x && !f[x]) sz[cur] += dfssz(x, cur);
return sz[cur];
}
ll cen (ll cur, ll par, ll now) {
for (auto &[x, y]: v[cur]) if (par != x && !f[x] && sz[x] * 2 > now) return cen(x, cur, now);
return cur;
}
void dfs (ll cur, ll par, ll dist, ll len) {
if (dist > d) return; u[rpar].emplace_back(dist, len); t.emplace_back(dist);
for (auto &[x, y]: v[cur]) if (par != x && !f[x]) dfs(x, cur, dist + y, len + 1);
}
void upd (ll cur) {
for (auto &[x, y]: u[cur]) if (x <= d && mn[d - x] != 1e12) ans = min(ans, mn[d - x] + y);
for (auto &[x, y]: u[cur]) mn[x] = min(mn[x], y);
}
void decom (ll cur) {
cur = cen(cur, 0, dfssz(cur, 0)); f[cur] = 1; mn[0] = 0;
for (auto &[x, y]: v[cur]) if (!f[x]) rpar = x, dfs(x, 0, y, 1), upd(x);
for (auto &e: t) mn[e] = 1e12;
for (auto &[x, y]: v[cur]) if (!f[x]) u[x].clear();
for (auto &[x, y]: v[cur]) if (!f[x]) decom(x);
}
int best_path(int n, int K, int h[][2], int l[]) {
d = K;
for (int i = 0; i < MxK; i++) mn[i] = 1e12;
for (int i = 0; i < n - 1; i++) h[i][0]++, h[i][1]++;
for (int i = 0; i < n - 1; i++) v[h[i][0]].emplace_back(h[i][1], l[i]), v[h[i][1]].emplace_back(h[i][0], l[i]);
decom(1);
return (ans == 1e12 ? -1 : ans);
}
컴파일 시 표준 에러 (stderr) 메시지
race.cpp: In function 'void dfs(ll, ll, ll, ll)':
race.cpp:26:3: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
26 | if (dist > d) return; u[rpar].emplace_back(dist, len); t.emplace_back(dist);
| ^~
race.cpp:26:25: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
26 | if (dist > d) return; u[rpar].emplace_back(dist, len); t.emplace_back(dist);
| ^
# | 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... |