# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
133433 |
2019-07-20T16:39:18 Z |
tdwn |
Mag (COCI16_mag) |
C++17 |
|
1825 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]);
}
}
}
sort(v.rbegin(), v.rend());
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;
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 |
25 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 |
1412 ms |
111812 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
23 ms |
23800 KB |
Output is correct |
2 |
Correct |
1706 ms |
187088 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1741 ms |
184088 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1584 ms |
78384 KB |
Output is correct |
2 |
Correct |
1213 ms |
64212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1690 ms |
82196 KB |
Output is correct |
2 |
Correct |
223 ms |
29688 KB |
Output is correct |
3 |
Correct |
1825 ms |
188332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
215 ms |
29480 KB |
Output is correct |
2 |
Correct |
1595 ms |
79268 KB |
Output is correct |
3 |
Correct |
1006 ms |
51884 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1526 ms |
76408 KB |
Output is correct |
2 |
Correct |
1703 ms |
77880 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1622 ms |
79304 KB |
Output is correct |
2 |
Correct |
1012 ms |
51888 KB |
Output is correct |