# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
133444 |
2019-07-20T17:13:49 Z |
tdwn |
Mag (COCI16_mag) |
C++17 |
|
1925 ms |
203996 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]);
}
//cout<<"Updating "<<node<<" from "<<i<<" - "<<dp[i][0]<<" "<<dp[i][1]<<"\n";
result2 = max(result2, max_0 + dp[i][1]);
result2 = max(result2, max_1 + dp[i][0]);
max_0 = max(max_0, dp[node][0]);
max_1 = max(max_1, dp[node][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 |
24 ms |
23928 KB |
Output is correct |
2 |
Correct |
24 ms |
23928 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
24 ms |
23800 KB |
Output is correct |
2 |
Correct |
25 ms |
23928 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1494 ms |
117864 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
23 ms |
23800 KB |
Output is correct |
2 |
Correct |
1779 ms |
202424 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1841 ms |
199540 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1726 ms |
78408 KB |
Output is correct |
2 |
Correct |
1233 ms |
64248 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1745 ms |
79424 KB |
Output is correct |
2 |
Correct |
227 ms |
29404 KB |
Output is correct |
3 |
Correct |
1925 ms |
203996 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
216 ms |
29432 KB |
Output is correct |
2 |
Correct |
1685 ms |
79456 KB |
Output is correct |
3 |
Correct |
1029 ms |
52048 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1590 ms |
75712 KB |
Output is correct |
2 |
Correct |
1747 ms |
77744 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1750 ms |
79516 KB |
Output is correct |
2 |
Correct |
1054 ms |
51884 KB |
Output is correct |