# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
173088 |
2020-01-03T10:39:25 Z |
VEGAnn |
Hard route (IZhO17_road) |
C++14 |
|
404 ms |
1144 KB |
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define sz(x) ((int)x.size())
#define MP make_pair
#define ft first
#define sd second
#define pii pair<int, int>
#define PB push_back
using namespace std;
using namespace __gnu_pbds;
template <class T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
const int N = 5100;
const int oo = 2e9;
vector<int> g[N];
int n, ans = -1, kol = 0, mx[N];
void build_sz(int v, int p){
mx[v] = 0;
for (int u : g[v]){
if (u == p) continue;
build_sz(u, v);
mx[v] = max(mx[v], mx[u] + 1);
}
}
void dfs(int v, int p, int len, int cmax){
if (sz(g[v]) == 1 && p >= 0){
int clen = len * cmax;
if (ans < clen){
ans = clen;
kol = 0;
}
if (ans == clen)
kol++;
return;
}
int mx1 = -1, mx2 = -1, n1 = -1, n2 = -1;
for (int u : g[v]){
if (u == p) continue;
if (mx1 < mx[u] + 1){
swap(mx1, mx2);
swap(n1, n2);
mx1 = mx[u] + 1;
n1 = u;
} else if (mx2 < mx[u] + 1){
mx2 = mx[u] + 1;
n2 = u;
}
}
for (int u : g[v]){
if (u == p) continue;
if (n1 == u)
dfs(u, v, len + 1, max(cmax, mx2));
else dfs(u, v, len + 1, max(cmax, mx1));
}
}
int main(){
ios_base::sync_with_stdio(0); cin.tie(0);
cin >> n;
for (int i = 1; i < n; i++){
int x, y; cin >> x >> y;
x--; y--;
g[x].PB(y);
g[y].PB(x);
}
for (int i = 0; i < n; i++)
if (sz(g[i]) == 1){
build_sz(i, -1);
dfs(i, -1, 0, 0);
}
cout << ans << " " << (kol >> 1);
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
504 KB |
Output is correct |
2 |
Correct |
2 ms |
504 KB |
Output is correct |
3 |
Correct |
2 ms |
504 KB |
Output is correct |
4 |
Correct |
2 ms |
504 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
504 KB |
Output is correct |
8 |
Correct |
2 ms |
504 KB |
Output is correct |
9 |
Correct |
2 ms |
504 KB |
Output is correct |
10 |
Correct |
2 ms |
504 KB |
Output is correct |
11 |
Correct |
2 ms |
504 KB |
Output is correct |
12 |
Correct |
2 ms |
504 KB |
Output is correct |
13 |
Correct |
2 ms |
504 KB |
Output is correct |
14 |
Correct |
2 ms |
504 KB |
Output is correct |
15 |
Correct |
2 ms |
504 KB |
Output is correct |
16 |
Correct |
2 ms |
504 KB |
Output is correct |
17 |
Correct |
2 ms |
504 KB |
Output is correct |
18 |
Correct |
2 ms |
504 KB |
Output is correct |
19 |
Correct |
2 ms |
504 KB |
Output is correct |
20 |
Correct |
2 ms |
504 KB |
Output is correct |
21 |
Correct |
2 ms |
504 KB |
Output is correct |
22 |
Correct |
2 ms |
504 KB |
Output is correct |
23 |
Correct |
2 ms |
504 KB |
Output is correct |
24 |
Correct |
2 ms |
504 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
504 KB |
Output is correct |
2 |
Correct |
2 ms |
504 KB |
Output is correct |
3 |
Correct |
2 ms |
504 KB |
Output is correct |
4 |
Correct |
2 ms |
504 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
504 KB |
Output is correct |
8 |
Correct |
2 ms |
504 KB |
Output is correct |
9 |
Correct |
2 ms |
504 KB |
Output is correct |
10 |
Correct |
2 ms |
504 KB |
Output is correct |
11 |
Correct |
2 ms |
504 KB |
Output is correct |
12 |
Correct |
2 ms |
504 KB |
Output is correct |
13 |
Correct |
2 ms |
504 KB |
Output is correct |
14 |
Correct |
2 ms |
504 KB |
Output is correct |
15 |
Correct |
2 ms |
504 KB |
Output is correct |
16 |
Correct |
2 ms |
504 KB |
Output is correct |
17 |
Correct |
2 ms |
504 KB |
Output is correct |
18 |
Correct |
2 ms |
504 KB |
Output is correct |
19 |
Correct |
2 ms |
504 KB |
Output is correct |
20 |
Correct |
2 ms |
504 KB |
Output is correct |
21 |
Correct |
2 ms |
504 KB |
Output is correct |
22 |
Correct |
2 ms |
504 KB |
Output is correct |
23 |
Correct |
2 ms |
504 KB |
Output is correct |
24 |
Correct |
2 ms |
504 KB |
Output is correct |
25 |
Correct |
326 ms |
888 KB |
Output is correct |
26 |
Correct |
298 ms |
932 KB |
Output is correct |
27 |
Correct |
299 ms |
916 KB |
Output is correct |
28 |
Correct |
304 ms |
888 KB |
Output is correct |
29 |
Correct |
391 ms |
888 KB |
Output is correct |
30 |
Correct |
389 ms |
888 KB |
Output is correct |
31 |
Correct |
397 ms |
888 KB |
Output is correct |
32 |
Correct |
387 ms |
1016 KB |
Output is correct |
33 |
Correct |
7 ms |
888 KB |
Output is correct |
34 |
Correct |
7 ms |
888 KB |
Output is correct |
35 |
Correct |
7 ms |
1016 KB |
Output is correct |
36 |
Correct |
7 ms |
1020 KB |
Output is correct |
37 |
Correct |
5 ms |
1016 KB |
Output is correct |
38 |
Correct |
5 ms |
1144 KB |
Output is correct |
39 |
Correct |
7 ms |
888 KB |
Output is correct |
40 |
Correct |
8 ms |
760 KB |
Output is correct |
41 |
Correct |
12 ms |
760 KB |
Output is correct |
42 |
Correct |
22 ms |
632 KB |
Output is correct |
43 |
Correct |
37 ms |
632 KB |
Output is correct |
44 |
Correct |
64 ms |
632 KB |
Output is correct |
45 |
Correct |
137 ms |
704 KB |
Output is correct |
46 |
Correct |
163 ms |
632 KB |
Output is correct |
47 |
Correct |
389 ms |
736 KB |
Output is correct |
48 |
Correct |
404 ms |
760 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
504 KB |
Output is correct |
2 |
Correct |
2 ms |
504 KB |
Output is correct |
3 |
Correct |
2 ms |
504 KB |
Output is correct |
4 |
Correct |
2 ms |
504 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
504 KB |
Output is correct |
8 |
Correct |
2 ms |
504 KB |
Output is correct |
9 |
Correct |
2 ms |
504 KB |
Output is correct |
10 |
Correct |
2 ms |
504 KB |
Output is correct |
11 |
Correct |
2 ms |
504 KB |
Output is correct |
12 |
Correct |
2 ms |
504 KB |
Output is correct |
13 |
Correct |
2 ms |
504 KB |
Output is correct |
14 |
Correct |
2 ms |
504 KB |
Output is correct |
15 |
Correct |
2 ms |
504 KB |
Output is correct |
16 |
Correct |
2 ms |
504 KB |
Output is correct |
17 |
Correct |
2 ms |
504 KB |
Output is correct |
18 |
Correct |
2 ms |
504 KB |
Output is correct |
19 |
Correct |
2 ms |
504 KB |
Output is correct |
20 |
Correct |
2 ms |
504 KB |
Output is correct |
21 |
Correct |
2 ms |
504 KB |
Output is correct |
22 |
Correct |
2 ms |
504 KB |
Output is correct |
23 |
Correct |
2 ms |
504 KB |
Output is correct |
24 |
Correct |
2 ms |
504 KB |
Output is correct |
25 |
Correct |
326 ms |
888 KB |
Output is correct |
26 |
Correct |
298 ms |
932 KB |
Output is correct |
27 |
Correct |
299 ms |
916 KB |
Output is correct |
28 |
Correct |
304 ms |
888 KB |
Output is correct |
29 |
Correct |
391 ms |
888 KB |
Output is correct |
30 |
Correct |
389 ms |
888 KB |
Output is correct |
31 |
Correct |
397 ms |
888 KB |
Output is correct |
32 |
Correct |
387 ms |
1016 KB |
Output is correct |
33 |
Correct |
7 ms |
888 KB |
Output is correct |
34 |
Correct |
7 ms |
888 KB |
Output is correct |
35 |
Correct |
7 ms |
1016 KB |
Output is correct |
36 |
Correct |
7 ms |
1020 KB |
Output is correct |
37 |
Correct |
5 ms |
1016 KB |
Output is correct |
38 |
Correct |
5 ms |
1144 KB |
Output is correct |
39 |
Correct |
7 ms |
888 KB |
Output is correct |
40 |
Correct |
8 ms |
760 KB |
Output is correct |
41 |
Correct |
12 ms |
760 KB |
Output is correct |
42 |
Correct |
22 ms |
632 KB |
Output is correct |
43 |
Correct |
37 ms |
632 KB |
Output is correct |
44 |
Correct |
64 ms |
632 KB |
Output is correct |
45 |
Correct |
137 ms |
704 KB |
Output is correct |
46 |
Correct |
163 ms |
632 KB |
Output is correct |
47 |
Correct |
389 ms |
736 KB |
Output is correct |
48 |
Correct |
404 ms |
760 KB |
Output is correct |
49 |
Runtime error |
3 ms |
760 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
50 |
Halted |
0 ms |
0 KB |
- |