# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
133437 |
2019-07-20T16:48:36 Z |
tdwn |
Mag (COCI16_mag) |
C++17 |
|
1702 ms |
140308 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 dp[maxn], result1;
ll result2;
ll dpup[maxn];
void dfs(int node, int p) {
vector<ll>v;
if(p != -1) {
if(arr[node] == 1) dpup[node] = 1 + dpup[p];
else dpup[node] = 0;
}
else if(arr[node] == 1) dpup[node] = 1;
for(int i:g[node]) {
if(i != p) {
dfs(i, node);
if(arr[i] == 1) {
v.pb(dp[i]);
}
}
}
if(arr[node] == 2) {
v.pb(dpup[p]);
v.pb(0);
sort(v.rbegin(), v.rend());
//cout<<node<<": "<<v[0]<<" "<<v[1]<<"\n";
result2 = max(result2, v[0] + v[1] + 1LL);
return;
}
if(arr[node] != 1) return;
sort(v.rbegin(), v.rend());
if(v.size() == 0) {
dp[node] = 1LL;
result1 = max(result1, dp[node]);
}
if(v.size() == 1) {
dp[node] = 1 + v[0];
result1 = max(result1, dp[node]);
}
else if(v.size() > 1){
dp[node] = 1 + v[0];
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(400001, -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 |
Incorrect |
23 ms |
23800 KB |
Output isn't 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 |
1397 ms |
111668 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
23 ms |
23804 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1702 ms |
140308 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1596 ms |
78488 KB |
Output is correct |
2 |
Correct |
1208 ms |
64176 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1656 ms |
82264 KB |
Output is correct |
2 |
Incorrect |
190 ms |
27876 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
181 ms |
27768 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1517 ms |
76420 KB |
Output is correct |
2 |
Correct |
1702 ms |
77944 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1608 ms |
79080 KB |
Output is correct |
2 |
Correct |
1030 ms |
51860 KB |
Output is correct |