이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "race.h"
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast,unroll-loops")
#pragma loop-opt(on)
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,avx,avx2,fma,tune=native")
#define pb push_back
#define eb emplace_back
#define push emplace
#define lb(x, v) lower_bound(all(x), v)
#define ub(x, v) upper_bound(all(x), v)
#define sz(x) (int)(x.size())
#define re(x) reverse(all(x))
#define uni(x) x.resize(unique(all(x)) - x.begin())
#define all(x) x.begin(), x.end()
#define mem(x, v) memset(x, v, sizeof x);
#define pii pair<int, int>
#define inf 1e9
#define INF 1e18
#define mod 1000000007
#define F first
#define S second
#define IO ios_base::sync_with_stdio(0); cin.tie(0);
#define chmax(a, b) (a = (b > a ? b : a))
#define chmin(a, b) (a = (b < a ? b : a))
using namespace std;
void trace_() {cerr << "\n";}
template<typename T1, typename... T2> void trace_(T1 t1, T2... t2) {cerr << ' ' << t1; trace_(t2...); }
#define trace(...) cerr << "[" << #__VA_ARGS__ << "] :", trace_(__VA_ARGS__);
const int mxN = 2e5 + 5;
int n, k, ans = inf, sz[mxN], bson[mxN], bw[mxN], dep[mxN];
vector<pii> g[mxN];
void pre(int u, int p) {
sz[u] = 1;
int id = -1, ww = 0;
for (auto [v, w] : g[u]) {
if (v == p) continue;
dep[v] = dep[u] + w;
pre(v, u);
sz[u] += sz[v];
if (id == -1 or sz[id] < sz[v]) id = v, ww = w;
}
bson[u] = id;
bw[u] = ww;
}
map<int, int> dfs(int u, int p) {
map<int, int> mp, t;
int d = 0;
if (~bson[u]) {
mp = dfs(bson[u], u);
d = mp[-1] + 1;
mp.erase(-1);
}
mp[dep[u]] = -d;
for (auto [v, w] : g[u]) {
if (v == bson[u] or v == p) continue;
t = dfs(v, u);
int td = t[-1] + 1;
t.erase(-inf);
for (auto [depth, step] : t) {
if (mp.count(k + 2 * dep[u] - depth)) {
chmin(ans, step + mp[k + 2 * dep[u] - depth] + d + td);
}
if (mp.count(depth)) {
chmin(mp[depth], step + td - d);
} else {
mp[depth] = step + td - d;
}
}
}
if (mp.count(k + dep[u])) {
ans = min(ans, mp[k + dep[u]] + d);
}
mp[-1] = d;
return mp;
}
int best_path(int N, int K, int H[][2], int L[]) {
n = N; k = K;
for (int i = 0; i < n - 1; i ++) {
g[H[i][0]].pb({H[i][1], L[i]});
g[H[i][1]].pb({H[i][0], L[i]});
bson[i] = -1;
}
bson[n - 1] = -1;
pre(0, -1);
dfs(0, -1);
if (ans > n) ans = -1;
return ans;
}
컴파일 시 표준 에러 (stderr) 메시지
race.cpp:4: warning: ignoring '#pragma loop ' [-Wunknown-pragmas]
4 | #pragma loop-opt(on)
|
# | 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... |