Submission #167646

#TimeUsernameProblemLanguageResultExecution timeMemory
167646HungAnhGoldIBO2020Mag (COCI16_mag)C++14
24 / 120
520 ms139468 KiB
#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)

mag.cpp: In function 'int main()':
mag.cpp:34:14: warning: unused variable 'l' [-Wunused-variable]
  int n,i,j,k,l,min1=inf;
              ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...