# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
133442 |
2019-07-20T17:10:19 Z |
tdwn |
Mag (COCI16_mag) |
C++17 |
|
1873 ms |
199472 KB |
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
using namespace std;
const int maxn = 1000100;
vector<int>g[maxn];
ll arr[maxn], n;
ll result1;
ll result2;
ll dp[maxn][2];
void dfs(int node, int p) {
if(arr[node] == 1) dp[node][0] = 1;
if(arr[node] == 2) dp[node][1] = 1;
vector<ll>v;
ll max_0 = dp[node][0];
ll max_1 = dp[node][1];
for(int i:g[node]) {
if(i != p) {
dfs(i, node);
if(arr[node] == 1) {
if(arr[i] == 1) {
dp[node][0] = max(dp[node][0], 1 + dp[i][0]);
v.pb(dp[i][0]);
}
if(dp[i][1] != 0) dp[node][1] = max(dp[node][1], 1 + dp[i][1]);
}
else if(arr[node] == 2) {
dp[node][1] = max(dp[node][1], 1 + dp[i][0]);
}
result2 = max(result2, max_0 + dp[i][1] + 1);
result2 = max(result2, max_1 + dp[i][0] + 1);
max_0 = max(max_0, dp[i][0]);
max_1 = max(max_1, dp[i][1]);
}
}
result1 = max(result1, dp[node][0]);
result2 = max(result2, dp[node][1]);
v.pb(0);
v.pb(0);
sort(v.rbegin(), v.rend());
if(arr[node] == 2) {
result2 = max(result2, v[0] + v[1] + 1);
}
else if(arr[node] == 1) {
result1 = max(result1, v[0] + v[1] + 1);
}
}
int main() {
cin>>n;
ll a, b;
for(int i=0;i<n-1;i++) {
cin>>a>>b;
g[a].pb(b);
g[b].pb(a);
}
ll minval = LLONG_MAX;
for(int i=1;i<=n;i++) {
cin>>arr[i];
minval = min(minval, arr[i]);
}
if(minval != 1) {
cout<<minval<<"/1\n";
}
else {
dfs(1, -1);
if(result2 > 2*result1) {
cout<<"2/"<<result2<<"\n";
}
else {
cout<<"1/"<<result1<<"\n";
}
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
25 ms |
23932 KB |
Output is correct |
2 |
Correct |
24 ms |
23800 KB |
Output is 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 |
Correct |
1481 ms |
117796 KB |
Output is 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 |
1873 ms |
199472 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1688 ms |
78364 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1705 ms |
79460 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
215 ms |
29452 KB |
Output is correct |
2 |
Incorrect |
1682 ms |
79500 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1626 ms |
75684 KB |
Output is correct |
2 |
Incorrect |
1756 ms |
77724 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1709 ms |
79380 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |