제출 #226757

#제출 시각아이디문제언어결과실행 시간메모리
226757staniewzki경주 (Race) (IOI11_race)C++17
21 / 100
3066 ms10208 KiB
#include<bits/stdc++.h> using namespace std; #define REP(i, n) for(int i = 0; i < n; i++) #define FOR(i, a, b) for(int i = a; i <= b; i++) #define ST first #define ND second ostream& operator<<(ostream &out, string str) { for(char c : str) out << c; return out; } template<class L, class R> ostream& operator<<(ostream &out, pair<L, R> p) { return out << "(" << p.ST << ", " << p.ND << ")"; } template<class T> auto operator<<(ostream &out, T a) -> decltype(a.begin(), out) { out << "{"; for(auto it = a.begin(); it != a.end(); it = next(it)) out << (it != a.begin() ? ", " : "") << *it; return out << "}"; } void dump() { cerr << "\n"; } template<class T, class... Ts> void dump(T a, Ts... x) { cerr << a << ", "; dump(x...); } #ifdef DEBUG # define debug(...) cerr << "[" #__VA_ARGS__ "]: ", dump(__VA_ARGS__) #else # define debug(...) false #endif template<class T> int size(T && a) { return (int) a.size(); } using LL = long long; using PII = pair<int, int>; #include "race.h" int best_path(int n, int k, int h[][2], int l[]) { vector<vector<PII>> adj(n); REP(i, n - 1) { adj[h[i][0]].emplace_back(h[i][1], l[i]); adj[h[i][1]].emplace_back(h[i][0], l[i]); } vector<int> sub(n), del(n); function<void(int, int)> get_sub = [&](int v, int p) { sub[v] = 1; for(auto &[u, w] : adj[v]) { if(u != p && !del[u]) { get_sub(u, v); sub[u] += sub[v]; } } }; function<int(int, int, int)> get_centro = [&](int v, int p, int tree) { bool is_centro = true; if((tree - sub[v]) * 2 >= tree) is_centro = false; for(auto &[u, w] : adj[v]) { if(u != p && !del[u]) { int r = get_centro(u, v, tree); if(r != -1) return r; if(sub[u] * 2 >= tree) is_centro = false; } } if(is_centro) return v; return -1; }; int inf = 1e9, ans = inf; vector<int> opt(k + 1, inf); function<void(int, int, int, int, int)> get_ans = [&](int v, int p, int dep, int dst, int type) { if(dst > k) return; if(type == 1) ans = min(ans, dep + opt[k - dst]); if(type == 2) opt[dst] = min(opt[dst], dep); if(type == 3) opt[dst] = inf; for(auto &[u, w] : adj[v]) if(u != p && !del[u]) get_ans(u, v, dep + 1, dst + w, type); }; function<void(int)> decomp = [&](int v) { get_sub(v, -1); v = get_centro(v, -1, sub[v]); opt[0] = 0; for(auto &[u, w] : adj[v]) if(!del[u]) { get_ans(u, v, 1, w, 1); get_ans(u, v, 1, w, 2); } for(auto &[u, w] : adj[v]) if(!del[u]) get_ans(u, v, 1, w, 3); del[v] = true; for(auto &[u, w] : adj[v]) if(!del[u]) decomp(u); }; decomp(0); if(ans >= inf) ans = -1; return ans; }

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

race.cpp: In lambda function:
race.cpp:54:18: warning: unused variable 'w' [-Wunused-variable]
   for(auto &[u, w] : adj[v]) {
                  ^
race.cpp: In lambda function:
race.cpp:66:18: warning: unused variable 'w' [-Wunused-variable]
   for(auto &[u, w] : adj[v]) {
                  ^
race.cpp: In lambda function:
race.cpp:102:18: warning: unused variable 'w' [-Wunused-variable]
   for(auto &[u, w] : adj[v]) if(!del[u])
                  ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...