Submission #720571

#TimeUsernameProblemLanguageResultExecution timeMemory
720571Ahmed57Mag (COCI16_mag)C++14
0 / 120
946 ms146164 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){ 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 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...