제출 #784664

#제출 시각아이디문제언어결과실행 시간메모리
784664vjudge1Race (IOI11_race)C++17
0 / 100
1524 ms262144 KiB
#include <bits/stdc++.h> #include "race.h" using namespace std; #define endl '\n' #define ll long long #define all(x) x.begin(), x.end() vector<pair<int, int>> g[200005]; bool processed[200005]; int sz[200005]; int getSize(int cur, int par = -1) { sz[cur] = 1; for (auto next : g[cur]) { if (next.first != par && !processed[next.first]) sz[cur] += getSize(next.first, cur); } return sz[cur]; } int getCentroid(int cur, int des, int par = -1) { for (auto next : g[cur]) { if (next.first != par && !processed[cur] && sz[cur] > des / 2) return getCentroid(next.first, des, cur); } return cur; } int ans = 10e7, k; map<int, int> cnt; set<int> s; void solve(int cur, int par, int depth, int sum, bool t) { if (sum > k || depth >= ans) return; if (sum == k) { ans = depth; return; } s.insert(sum); if (!t) if (cnt.count(k - sum)) ans = min(ans, depth + cnt[k - sum]); else cnt[sum] = min(cnt[sum], depth); for (auto next : g[cur]) { if (next.first != par && !processed[next.first] && sum + next.second <= k) { solve(next.first, cur, depth + 1, sum + next.second, t); } } } void decompose(int cur = 0) { getSize(cur); cur = getCentroid(cur, getSize(cur)); processed[cur] = 1; for (auto next : g[cur]) { if (!processed[next.first] && next.second <= k) { solve(cur, -1, 1, next.second, 0); solve(cur, -1, 1, next.second, 1); } } for (auto x : s) cnt[x] = 10e7; s.clear(); for (auto next : g[cur]) { if (!processed[next.first]) decompose(next.first); } } int best_path(int N, int K, int H[][2], int L[]) { k = K; for (int i = 0; i < N - 1; i++) { g[H[i][0]].push_back({H[i][1], L[i]}); g[H[i][1]].push_back({H[i][0], L[i]}); } decompose(); if (ans == 10e7) return -1; else return ans; }

컴파일 시 표준 에러 (stderr) 메시지

race.cpp: In function 'void solve(int, int, int, int, bool)':
race.cpp:41:8: warning: suggest explicit braces to avoid ambiguous 'else' [-Wdangling-else]
   41 |     if (!t) if (cnt.count(k - sum)) ans = min(ans, depth + cnt[k - sum]);
      |        ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...