Submission #720587

#TimeUsernameProblemLanguageResultExecution timeMemory
720587Ahmed57Mag (COCI16_mag)C++14
24 / 120
842 ms147616 KiB
//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){ long long ch = (ma[i]==1?1:0); for(auto j:adj[i]){ if(j!=pr){ calc(j,i); if(ma[i]==1)ch = max(ch,lon[j]+1); } } 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<<2<<"/"<<2*maa+1<<endl; }
#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...