Submission #490685

# Submission time Handle Problem Language Result Execution time Memory
490685 2021-11-28T16:43:54 Z naal Mag (COCI16_mag) C++14
0 / 120
905 ms 161144 KB
#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
1 Correct 13 ms 23756 KB Output is correct
2 Incorrect 13 ms 23756 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 16 ms 23788 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 709 ms 98916 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 12 ms 23756 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 893 ms 161144 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 776 ms 70492 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 905 ms 72804 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 102 ms 29060 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 793 ms 68360 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 789 ms 71420 KB Output isn't correct
2 Halted 0 ms 0 KB -