Submission #720571

# Submission time Handle Problem Language Result Execution time Memory
720571 2023-04-08T13:35:10 Z Ahmed57 Mag (COCI16_mag) C++14
0 / 120
946 ms 146164 KB
//LCA
#include <bits/stdc++.h>

using namespace std;
#define int long long
vector<int> adj[1000001];
long long ma[1000001];
long long lon[1000001];
int n ;
void calc(int i,int pr){
    int ch = (ma[i]==1?1:0);
    for(auto j:adj[i]){
        if(j!=pr){
            calc(j,i);
            ch = max(ch,lon[j]+(ma[i]==1?1:0));
        }
    }
    lon[i] = ch;
}
long long maa = 0;
void dfs(int i,int pr){
    maa = max(maa,lon[i]);
    for(auto j:adj[i]){
        if(j==pr)continue;
        dfs(j,i);
    }
    if(ma[i]==1){
        long long firstma = 0 , secondma = 0;
        for(auto j:adj[i]){
            if(j==pr)continue;
            if(firstma<=lon[j]){
                secondma = firstma;
                firstma = lon[j];
            }else if(secondma<=lon[j]){
                secondma = lon[j];
            }
        }
        maa = max(maa,firstma+secondma+1);
    }
}
signed main(){
    cin>>n;
    for(int i = 0;i<n-1;i++){
        int a,b;cin>>a>>b;
        adj[a].push_back(b);
        adj[b].push_back(a);
    }
    long long mi = 1e18;
    for(int i = 0;i<n;i++){
        cin>>ma[i+1];
        mi = min(mi,ma[i+1]);
    }
    calc(1,0);
    dfs(1,0);
    if(mi!=1)cout<<mi<<"/"<<1<<endl;
    else cout<<1<<"/"<<maa<<endl;
}
# Verdict Execution time Memory Grader output
1 Correct 13 ms 23764 KB Output is correct
2 Incorrect 12 ms 23828 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 12 ms 23764 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 722 ms 86316 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 12 ms 23764 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 946 ms 146164 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 817 ms 70424 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 835 ms 72948 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 107 ms 28992 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 767 ms 67864 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 825 ms 71140 KB Output isn't correct
2 Halted 0 ms 0 KB -