# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
133439 |
2019-07-20T16:51:58 Z |
tdwn |
Mag (COCI16_mag) |
C++17 |
|
1734 ms |
140396 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) {
if(p == -1) v.pb(0);
else 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 |
23800 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 |
1422 ms |
111496 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
34 ms |
23800 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1734 ms |
140396 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1582 ms |
78404 KB |
Output is correct |
2 |
Correct |
1169 ms |
64248 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1654 ms |
82072 KB |
Output is correct |
2 |
Incorrect |
188 ms |
27868 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
189 ms |
27848 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1551 ms |
76300 KB |
Output is correct |
2 |
Correct |
1647 ms |
77936 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1613 ms |
79248 KB |
Output is correct |
2 |
Correct |
1004 ms |
51960 KB |
Output is correct |