# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
133440 |
2019-07-20T17:00:06 Z |
tdwn |
Mag (COCI16_mag) |
C++17 |
|
1895 ms |
204132 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;
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]);
}
}
}
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 |
23800 KB |
Output is correct |
2 |
Correct |
24 ms |
23800 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
25 ms |
23928 KB |
Output is correct |
2 |
Correct |
25 ms |
23928 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1477 ms |
117792 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
23 ms |
23800 KB |
Output is correct |
2 |
Correct |
1783 ms |
202508 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1841 ms |
199564 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1704 ms |
78408 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1692 ms |
79580 KB |
Output is correct |
2 |
Correct |
226 ms |
29432 KB |
Output is correct |
3 |
Correct |
1895 ms |
204132 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
223 ms |
29432 KB |
Output is correct |
2 |
Incorrect |
1703 ms |
79420 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1607 ms |
75736 KB |
Output is correct |
2 |
Incorrect |
1759 ms |
77740 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1726 ms |
79540 KB |
Output is correct |
2 |
Correct |
1063 ms |
51828 KB |
Output is correct |