# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
167646 | 2019-12-09T08:07:52 Z | HungAnhGoldIBO2020 | Mag (COCI16_mag) | C++14 | 520 ms | 139468 KB |
#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
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 24 ms | 23928 KB | Output is correct |
2 | Correct | 23 ms | 23928 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 23 ms | 23928 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 416 ms | 87524 KB | Output isn't correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 24 ms | 23800 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 520 ms | 139468 KB | Output isn't correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 461 ms | 63480 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 440 ms | 64800 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 82 ms | 29176 KB | Output is correct |
2 | Incorrect | 456 ms | 64272 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 414 ms | 61700 KB | Output is correct |
2 | Incorrect | 449 ms | 62712 KB | Output isn't correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 463 ms | 64180 KB | Output is correct |
2 | Correct | 352 ms | 45176 KB | Output is correct |