# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
133436 |
2019-07-20T16:44:25 Z |
tdwn |
Mag (COCI16_mag) |
C++17 |
|
1775 ms |
188332 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(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 |
23800 KB |
Output is correct |
# |
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 |
Incorrect |
1469 ms |
111548 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
23 ms |
23800 KB |
Output is correct |
2 |
Correct |
1704 ms |
186968 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1727 ms |
184408 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1595 ms |
78456 KB |
Output is correct |
2 |
Correct |
1174 ms |
64124 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1659 ms |
82168 KB |
Output is correct |
2 |
Correct |
215 ms |
29432 KB |
Output is correct |
3 |
Correct |
1775 ms |
188332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
213 ms |
29436 KB |
Output is correct |
2 |
Correct |
1596 ms |
79352 KB |
Output is correct |
3 |
Correct |
1026 ms |
51832 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1526 ms |
76224 KB |
Output is correct |
2 |
Correct |
1670 ms |
77936 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1606 ms |
79272 KB |
Output is correct |
2 |
Correct |
1016 ms |
51832 KB |
Output is correct |