# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
679220 |
2023-01-07T18:45:21 Z |
ziduo |
Mag (COCI16_mag) |
C++14 |
|
433 ms |
223364 KB |
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define f first
#define s second
int vals[1000000];
int dp[1000000][2];
vector<int> edges[1000000];
pair<int, int> answer;
void rec(int u, int p){
for(int v: edges[u])if(v!=p)rec(v, u);
if(vals[u]>2){
dp[u][0] = 0;
dp[u][1] = 0;
return;
}
vector<int> use0;
vector<int> use1;
for(int v: edges[u])if(v!=p){
use0.push_back(dp[v][0]);
use1.push_back(dp[v][1]);
}
sort(use0.begin(), use0.end());
sort(use1.begin(), use1.end());
reverse(use0.begin(), use0.end());
reverse(use1.begin(), use1.end());
if(vals[u]==2){
dp[u][0] = 0;
if(use0.size()==0){
dp[u][1] = 1;
answer.s=max(answer.s, 1);
}
else{
dp[u][1] = use0[0]+1;
if(use0.size()==1)
answer.s=max(answer.s,use0[0]+1);
else
answer.s=max(answer.s,use0[0]+1+use0[1]);
}
}
else{
if(use0.size()==0){
dp[u][0] = 1;
dp[u][1] = 0;
answer.f=max(answer.f, 1);
}
else if(use0.size()==1){
dp[u][0] = use0[0]+1;
dp[u][1] = use1[0]+1;
answer.f=max(answer.f, dp[u][0]);
answer.s=max(answer.s, dp[u][1]);
}
else{
dp[u][0] = use0[0]+1;
dp[u][1] = use1[0]+1;
answer.f=max(answer.f, use0[0]+use0[1]+1);
answer.s=max(answer.s, use0[0]+use1[0]+1);
}
}
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int n;
cin>>n;
for(int i=0; i<n; i++)edges[i] = {};
for(int i=0; i<n-1; i++){
int u, v;cin>>u>>v;u--;v--;
edges[u].push_back(v);
edges[v].push_back(u);
}
answer.f=0; answer.s=0;
for(int i=0; i<n; i++)cin>>vals[i];
rec(0, -1);
if(answer.f==0&&answer.s==0){
int prin = vals[0];
for(int i=1; i<n; i++)prin = min(prin, vals[i]);
cout<<prin<<"/1\n";
}
else{
if(answer.f>answer.s/2)
cout<<"1/"<<answer.f<<'\n';
else{
if((answer.s%2)==0)cout<<"1/"<<(answer.s/2)<<'\n';
else cout<<"2/"<<answer.s<<'\n';
}
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
23860 KB |
Output is correct |
2 |
Correct |
13 ms |
23756 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
11 ms |
23764 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
328 ms |
120864 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
23764 KB |
Output is correct |
2 |
Correct |
426 ms |
221624 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
414 ms |
218472 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
340 ms |
66636 KB |
Output is correct |
2 |
Correct |
253 ms |
55624 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
350 ms |
72432 KB |
Output is correct |
2 |
Correct |
56 ms |
28212 KB |
Output is correct |
3 |
Correct |
433 ms |
223364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
62 ms |
28124 KB |
Output is correct |
2 |
Correct |
344 ms |
67892 KB |
Output is correct |
3 |
Correct |
276 ms |
45856 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
312 ms |
66780 KB |
Output is correct |
2 |
Correct |
351 ms |
66144 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
391 ms |
67736 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |