# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
167646 | HungAnhGoldIBO2020 | Mag (COCI16_mag) | C++14 | 520 ms | 139468 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;
const int N=1e6+2;
const int inf=1e9+7;
vector<int> adj[N];
int val[N],f[N],max1=0;
void dfs(int x,int p){
int mx=0;
if(val[x]==1){
f[x]=1;
}
for(int i:adj[x]){
if(i!=p){
dfs(i,x);
if(val[i]>1||val[x]>1){
continue;
}
if(f[x]<f[i]+1){
mx=f[x];
f[x]=f[i]+1;
}
else{
if(f[i]+1>mx){
mx=f[i]+1;
}
}
}
}
max1=max(max1,mx+f[x]-1);
}
signed main(){
ios::sync_with_stdio(0);
cin.tie(0);
int n,i,j,k,l,min1=inf;
cin>>n;
for(i=1;i<n;i++){
cin>>j>>k;
adj[j].push_back(k);
adj[k].push_back(j);
}
for(i=1;i<=n;i++){
cin>>val[i];
min1=min(min1,val[i]);
}
if(min1>1){
cout<<min1<<'/'<<1;
return 0;
}
dfs(1,1);
cout<<1<<'/'<<max1;
}
/*
5
1 2
2 4
1 3
5 2
2
1
1
1
3
*/
Compilation message (stderr)
# | 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... |