Submission #490686

#TimeUsernameProblemLanguageResultExecution timeMemory
490686naalMag (COCI16_mag)C++14
0 / 120
857 ms161220 KiB
#include <bits/stdc++.h> using namespace std; #define int long long const int N = 1e6 + 2; int n, w[N], f[N], res; vector <int> a[N]; priority_queue <int> q; void dfs(int u, int par) { if (w[u] == 1) f[u] = 1; while (q.size()) q.pop(); for (int v : a[u]) if (v != par) { dfs(v, u); if (w[u] == 1 && w[v] == 1) { f[u] = max(f[u], f[v] + 1); q.push(f[v] + 1); } } if (q.size() > 1) { int tmp = q.top(); q.pop(); tmp += q.top(); q.pop(); res = max(res, tmp - 1); } res = max(res, f[u]); } signed main() { cin >> n; for (int i = 1; i < n; i++) { int u, v; cin >> u >> v; a[u].push_back(v); a[v].push_back(u); } res = 1e9; for (int i = 1; i <= n; i++) { cin >> w[i]; res = min(res, w[i]); } if (res > 1) cout << res << "/1"; else { res = 1; dfs(1, 1); cout << "1/" << res; } 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...