# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
159704 |
2019-10-24T03:31:51 Z |
silxikys |
Mag (COCI16_mag) |
C++14 |
|
1754 ms |
189768 KB |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 1e6+6;
int n, a[N];
vector<int> adj[N];
int dp[N][2]; //0 is longest path w/ end at i, 1 is longest overall
void f(int i, int p) {
for (int j: adj[i]) {
if (j == p) continue;
f(j,i);
}
if (a[i] == 1) {
vector<int> v;
//cout << i << ": ";
for (int j: adj[i]) {
if (j == p) continue;
v.push_back(dp[j][0]);
//cout << dp[j][0] << ' ';
}
//cout << '\n';
sort(v.begin(),v.end(),greater<int>());
dp[i][0] = dp[i][1] = 1;
if (v.size() > 0) {
dp[i][0] += v[0];
dp[i][1] += v[0];
}
if (v.size() > 1) {
dp[i][1] += v[1];
}
}
}
int main() {
//ios_base::sync_with_stdio(false); cin.tie(NULL);
cin >> n;
int mn = 2e9;
for (int i = 0; i < n-1; i++) {
int a, b; cin >> a >> b;
adj[a].push_back(b);
adj[b].push_back(a);
}
for (int i = 1; i <= n; i++) {
cin >> a[i];
mn = min(mn,a[i]);
}
f(1,1);
int longest = 0;
for (int i = 1; i <= n; i++) {
longest = max(longest,dp[i][1]);
}
if (longest == 0) {
printf("%d/%d\n",mn,1);
}
else {
printf("%d/%d\n",1,longest);
}
}
# |
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 |
Incorrect |
25 ms |
23928 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1408 ms |
116212 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
23 ms |
23800 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1754 ms |
189768 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1611 ms |
82040 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1639 ms |
85128 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
192 ms |
29560 KB |
Output is correct |
2 |
Incorrect |
1585 ms |
82944 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1511 ms |
80556 KB |
Output is correct |
2 |
Incorrect |
1658 ms |
83100 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1617 ms |
82924 KB |
Output is correct |
2 |
Correct |
943 ms |
53584 KB |
Output is correct |