# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
245733 |
2020-07-07T09:42:33 Z |
Vladikus004 |
Mag (COCI16_mag) |
C++14 |
|
478 ms |
130296 KB |
#include <bits/stdc++.h>
#define inf 2e9
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
const int N = 1000000 + 3;
int n, x[N], d[N], dp[N], p[N], ans;
vector <vector <int> > v;
void dfs(int x){
pii mx = {0, 0};
p[x] = 1;
for (auto u: v[x]){
if (p[u]) continue;
dfs(u);
mx = max(mx, {mx.first, dp[u]});
mx = max(mx, {dp[u], mx.first});
dp[x] = max(dp[x], dp[u]);
}
if (d[x]) {
dp[x]++;
ans = max(ans, mx.first + mx.second + 1);
}else dp[x] = 0;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
#ifdef LOCAL
freopen("input.txt", "r", stdin);
#endif // LOCAL
cin >> n;
v.resize(n);
for (int i = 0; i < n - 1; i++){
int a, b;
cin >> a >> b;
--a; --b;
v[a].push_back(b);
v[b].push_back(a);
}
for (int i = 0; i < n; i++){
cin >> x[i];
if (x[i] == 1)
d[i] = 1;
}
dfs(0);
if (!ans){
ans = inf;
for (int i = 0; i < n; i++)
ans = min(ans, x[i]);
cout << ans << "/1";
return 0;
}
cout << "1/" << ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
5 ms |
384 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
378 ms |
82016 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
5 ms |
384 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
478 ms |
130296 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
426 ms |
70520 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
387 ms |
71400 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
64 ms |
7672 KB |
Output is correct |
2 |
Incorrect |
464 ms |
86136 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
402 ms |
65264 KB |
Output is correct |
2 |
Incorrect |
421 ms |
69368 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
438 ms |
71296 KB |
Output is correct |
2 |
Correct |
300 ms |
43768 KB |
Output is correct |