# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|
490685 | | naal | Mag (COCI16_mag) | C++14 | | 905 ms | 161144 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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);
}
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 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... |
# | 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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |