# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
365381 |
2021-02-11T14:36:02 Z |
FatihSolak |
Mag (COCI16_mag) |
C++17 |
|
505 ms |
149100 KB |
#include <bits/stdc++.h>
#define N 1000005
using namespace std;
vector<int> adj[N];
int arr[N];
int down[N];
int down2[N];
int d[N];
int up[N];
int maxi = 0,mini = 1e9;
void dfs(int v,int p){
for(auto u:adj[v]){
if(u == p)continue;
dfs(u,v);
if(arr[u] == 1){
down[v] = max(down[v],down[u] + 1);
if(down[v] == down[u] + 1)d[v] = u;
}
}
for(auto u:adj[v]){
if(u == p)continue;
if(d[v] != u && arr[u] == 1){
down2[v] = max(down2[v],down[u]+1);
}
}
}
void dfs2(int v,int p){
if(arr[p] == 1){
up[v] = up[p] + 1;
if(arr[v] == 1 && d[p] == v){
up[v] = max(up[v], down2[p]+1);
}
else up[v] = max(up[v], down[p]+1);
}
for(auto u:adj[v]){
if(u == p)continue;
dfs2(u,v);
}
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
int n;
cin >> n;
for(int i=1;i<n;i++){
int u,v;
cin >> u >> v;
adj[u].push_back(v);
adj[v].push_back(u);
}
for(int i=1;i<=n;i++){
cin >> arr[i];
}
dfs(1,0);
dfs2(1,0);
for(int i=1;i<=n;i++){
if(arr[i] == 1){
maxi = max(maxi,2*(1+down[i]+up[i]));
}
if(arr[i] == 2){
maxi = max(maxi,1+down[i]+up[i]);
}
mini = min(mini,arr[i]);
}
if(maxi == 0){
cout << mini << "/" <<1;
}
else if(maxi & 1){
cout << 2 << "/" << maxi;
}
else cout << 1 << "/" << maxi/2;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
16 ms |
23916 KB |
Output is correct |
2 |
Correct |
16 ms |
23916 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
16 ms |
23916 KB |
Output is correct |
2 |
Correct |
17 ms |
23916 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
401 ms |
92780 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
17 ms |
23788 KB |
Output is correct |
2 |
Correct |
505 ms |
148064 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
451 ms |
146028 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
397 ms |
70508 KB |
Output is correct |
2 |
Correct |
291 ms |
58476 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
374 ms |
71644 KB |
Output is correct |
2 |
Correct |
90 ms |
29036 KB |
Output is correct |
3 |
Correct |
465 ms |
149100 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
85 ms |
29036 KB |
Output is correct |
2 |
Correct |
393 ms |
71276 KB |
Output is correct |
3 |
Correct |
359 ms |
50028 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
354 ms |
67940 KB |
Output is correct |
2 |
Correct |
385 ms |
69996 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
397 ms |
71300 KB |
Output is correct |
2 |
Correct |
373 ms |
50028 KB |
Output is correct |