이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include "race.h"
#define sz(x) (int)x.size()
using namespace std;
using pii = pair<int, int>;
int ans = 1e9, k;
vector<vector<pii> > graph;
vector<int> dist, edges;
vector<map<int, int> > sets;
void precomp(int u, int p, int e, int d) {
edges[u] = e;
dist[u] = d;
for(auto &[v, w] : graph[u]) {
if(v == p) continue;
precomp(v, u, e + 1, d + w);
}
}
void dfs(int u, int p) {
sets[u][dist[u]] = edges[u];
for(auto &[v, w] : graph[u]) {
if(v == p) continue;
dfs(v, u);
if(sz(sets[u]) < sz(sets[v])) swap(sets[u], sets[v]);
for(auto &x : sets[v])
if(sets[u].count(k + 2 * dist[u] - x.first))
ans = min(ans, x.second + sets[u][k+2*dist[u]-x.first] - 2 * edges[u]);
for(auto &x : sets[v]) {
if(sets[u].count(x.first)) sets[u][x.first] = min(sets[u][x.first], x.second);
else sets[u][x.first] = x.second;
}
}
}
int best_path(int N, int K, int H[][2], int L[]) {
k = K;
graph.resize(N);
dist.resize(N);
edges.resize(N);
sets.resize(N);
for(int i=0; i<N-1; i++) {
graph[H[i][0]].push_back({ H[i][1], L[i] });
graph[H[i][1]].push_back({ H[i][0], L[i] });
}
precomp(0, 0, 0, 0);
dfs(0, 0);
return (ans == 1e9 ? -1 : ans);
}
컴파일 시 표준 에러 (stderr) 메시지
race.cpp: In function 'void precomp(int, int, int, int)':
race.cpp:17:15: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
17 | for(auto &[v, w] : graph[u]) {
| ^
race.cpp: In function 'void dfs(int, int)':
race.cpp:25:15: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
25 | for(auto &[v, w] : graph[u]) {
| ^
# | 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... |