제출 #383083

#제출 시각아이디문제언어결과실행 시간메모리
383083smax무제 (POI11_dyn)C++17
100 / 100
1484 ms33556 KiB
#include <bits/stdc++.h> using namespace std; #ifdef LOCAL #define DEBUG(...) debug(#__VA_ARGS__, __VA_ARGS__) #else #define DEBUG(...) 6 #endif template<typename T, typename S> ostream& operator << (ostream &os, const pair<T, S> &p) {return os << "(" << p.first << ", " << p.second << ")";} template<typename C, typename T = decay<decltype(*begin(declval<C>()))>, typename enable_if<!is_same<C, string>::value>::type* = nullptr> ostream& operator << (ostream &os, const C &c) {bool f = true; os << "["; for (const auto &x : c) {if (!f) os << ", "; f = false; os << x;} return os << "]";} template<typename T> void debug(string s, T x) {cerr << s << " = " << x << "\n";} template <typename T, typename... Args> void debug(string s, T x, Args... args) {for (int i=0, b=0; i<(int)s.size(); i++) if (s[i] == '(' || s[i] == '{') b++; else if (s[i] == ')' || s[i] == '}') b--; else if (s[i] == ',' && b == 0) {cerr << s.substr(0, i) << " = " << x << " | "; debug(s.substr(s.find_first_not_of(' ', i + 1)), args...); break;}} const int INF = 1e9; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n, m; cin >> n >> m; vector<int> d(n); for (int i=0; i<n; i++) cin >> d[i]; vector<vector<int>> adj(n); for (int i=0; i<n-1; i++) { int a, b; cin >> a >> b; a--, b--; adj[a].push_back(b); adj[b].push_back(a); } int k, cnt; auto dfs = [&] (auto &self, int u, int p) -> int { int ret = d[u] ? 0 : INF; for (int v : adj[u]) if (v != p) { int d = self(self, v, u); if (ret > d) swap(ret, d); if (ret <= 0 && d > 0 && d - ret <= k) ret = d; } if (ret == -k) { cnt++; ret = 1; } else if (ret <= 0) { ret--; } else { ret++; } return ret; }; int l = 0, r = n; while (l < r) { k = (l + r) / 2; cnt = 0; if (dfs(dfs, 0, -1) < 0) cnt++; if (cnt <= m) r = k; else l = k + 1; } cout << l << "\n"; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...