Submission #98269

# Submission time Handle Problem Language Result Execution time Memory
98269 2019-02-21T18:18:11 Z dalgerok Mag (COCI16_mag) C++17
24 / 120
549 ms 138460 KB
#include<bits/stdc++.h>
using namespace std;



const int N = 1e6 + 5;



int n, a[N], dp[N], ans = -1;
vector < int > g[N];


void dfs(int v, int pr = -1){
    int mx1 = 0, mx2 = 0;
    for(int to : g[v]){
        if(to != pr){
            dfs(to, v);
            if(dp[to] > mx1){
                mx2 = mx1;
                mx1 = dp[to];
            }
            else if(dp[to] > mx2){
                mx2 = dp[to];
            }
        }
    }
    if(a[v] == 1){
        dp[v] = mx1 + 1;
        ans = max(ans, mx1 + mx2 + 1);
    }
}

int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    cin >> n;
    for(int i = 1; i < n; i++){
        int x, y;
        cin >> x >> y;
        g[x].push_back(y);
        g[y].push_back(x);
    }
    ans = -1;
    for(int i = 1; i <= n; i++){
        cin >> a[i];
        if(a[i] == 1){
            ans = 1;
        }
    }
    dfs(1);
    if(ans != -1){
        return cout << "1/" << ans, 0;
    }
    ans = 2e9;
    for(int i = 1; i <= n; i++){
        ans = min(ans, a[i]);
    }
    cout << ans << "/1";
}
# Verdict Execution time Memory Grader output
1 Correct 26 ms 23928 KB Output is correct
2 Correct 23 ms 23936 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 24 ms 23900 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 386 ms 86392 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 28 ms 23808 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 549 ms 138460 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 450 ms 62740 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 399 ms 63844 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 110 ms 27932 KB Output is correct
2 Incorrect 450 ms 78636 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 393 ms 60868 KB Output is correct
2 Incorrect 433 ms 62300 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Correct 450 ms 63428 KB Output is correct
2 Correct 523 ms 44024 KB Output is correct