#include <bits/stdc++.h>
#define ll long long
#define F first
#define S second
using namespace std;
const int N = 5e5 + 5;
int n;
vector < int > g[N];
ll ans = -1, num;
ll D[N];
void dfs (int k, int p){
D[k] = 0;
for (int u: g[k]){
if (u == p)
continue;
dfs (u, k);
D[k] = max (D[k], D[u]);
}
D[k]++;
}
void go (int k, int p, ll d, ll dd){
if ((int)g[k].size() == 1 && p != 0){
if (ans == d * dd)
num++;
if (ans < d * dd){
ans = d * dd;
num = 1;
}
}
ll x = 0, y = 0;
for (int u: g[k]){
if (u == p)
continue;
y = max (y, D[u]);
if (x < y)
swap (x, y);
}
for (int u: g[k]){
if (u == p)
continue;
ll t = x;
if (t == D[u])
t = y;
go (u, k, d + 1, max (dd, t));
}
}
int main()
{
ios::sync_with_stdio(false);
cin>>n;
for (int i = 1; i < n; i++){
int u, v;
cin>>u>>v;
g[u].push_back (v);
g[v].push_back (u);
}
for (int S = 1; S <= n; S++){
if ((int)g[S].size() > 1)
continue;
dfs (S, 0);
go (S, 0, 0, 0);
}
cout<<ans<<" "<<num / 2<<endl;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
12024 KB |
Output is correct |
2 |
Correct |
13 ms |
12152 KB |
Output is correct |
3 |
Correct |
13 ms |
12152 KB |
Output is correct |
4 |
Correct |
12 ms |
12152 KB |
Output is correct |
5 |
Correct |
12 ms |
12024 KB |
Output is correct |
6 |
Correct |
10 ms |
12024 KB |
Output is correct |
7 |
Correct |
10 ms |
12024 KB |
Output is correct |
8 |
Correct |
11 ms |
12024 KB |
Output is correct |
9 |
Correct |
12 ms |
12152 KB |
Output is correct |
10 |
Correct |
10 ms |
12024 KB |
Output is correct |
11 |
Correct |
12 ms |
12152 KB |
Output is correct |
12 |
Correct |
10 ms |
12152 KB |
Output is correct |
13 |
Correct |
10 ms |
12152 KB |
Output is correct |
14 |
Correct |
10 ms |
12152 KB |
Output is correct |
15 |
Correct |
10 ms |
12152 KB |
Output is correct |
16 |
Correct |
10 ms |
12152 KB |
Output is correct |
17 |
Correct |
10 ms |
12152 KB |
Output is correct |
18 |
Correct |
10 ms |
12152 KB |
Output is correct |
19 |
Correct |
10 ms |
12152 KB |
Output is correct |
20 |
Correct |
10 ms |
12024 KB |
Output is correct |
21 |
Correct |
9 ms |
12028 KB |
Output is correct |
22 |
Correct |
10 ms |
12024 KB |
Output is correct |
23 |
Correct |
10 ms |
12024 KB |
Output is correct |
24 |
Correct |
10 ms |
12152 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
12024 KB |
Output is correct |
2 |
Correct |
13 ms |
12152 KB |
Output is correct |
3 |
Correct |
13 ms |
12152 KB |
Output is correct |
4 |
Correct |
12 ms |
12152 KB |
Output is correct |
5 |
Correct |
12 ms |
12024 KB |
Output is correct |
6 |
Correct |
10 ms |
12024 KB |
Output is correct |
7 |
Correct |
10 ms |
12024 KB |
Output is correct |
8 |
Correct |
11 ms |
12024 KB |
Output is correct |
9 |
Correct |
12 ms |
12152 KB |
Output is correct |
10 |
Correct |
10 ms |
12024 KB |
Output is correct |
11 |
Correct |
12 ms |
12152 KB |
Output is correct |
12 |
Correct |
10 ms |
12152 KB |
Output is correct |
13 |
Correct |
10 ms |
12152 KB |
Output is correct |
14 |
Correct |
10 ms |
12152 KB |
Output is correct |
15 |
Correct |
10 ms |
12152 KB |
Output is correct |
16 |
Correct |
10 ms |
12152 KB |
Output is correct |
17 |
Correct |
10 ms |
12152 KB |
Output is correct |
18 |
Correct |
10 ms |
12152 KB |
Output is correct |
19 |
Correct |
10 ms |
12152 KB |
Output is correct |
20 |
Correct |
10 ms |
12024 KB |
Output is correct |
21 |
Correct |
9 ms |
12028 KB |
Output is correct |
22 |
Correct |
10 ms |
12024 KB |
Output is correct |
23 |
Correct |
10 ms |
12024 KB |
Output is correct |
24 |
Correct |
10 ms |
12152 KB |
Output is correct |
25 |
Correct |
295 ms |
12536 KB |
Output is correct |
26 |
Correct |
298 ms |
12408 KB |
Output is correct |
27 |
Correct |
300 ms |
12536 KB |
Output is correct |
28 |
Correct |
296 ms |
12536 KB |
Output is correct |
29 |
Correct |
346 ms |
12516 KB |
Output is correct |
30 |
Correct |
381 ms |
12536 KB |
Output is correct |
31 |
Correct |
365 ms |
12508 KB |
Output is correct |
32 |
Correct |
372 ms |
12664 KB |
Output is correct |
33 |
Correct |
15 ms |
12536 KB |
Output is correct |
34 |
Correct |
14 ms |
12540 KB |
Output is correct |
35 |
Correct |
14 ms |
12536 KB |
Output is correct |
36 |
Correct |
15 ms |
12636 KB |
Output is correct |
37 |
Correct |
13 ms |
12636 KB |
Output is correct |
38 |
Correct |
12 ms |
12664 KB |
Output is correct |
39 |
Correct |
13 ms |
12408 KB |
Output is correct |
40 |
Correct |
15 ms |
12408 KB |
Output is correct |
41 |
Correct |
20 ms |
12280 KB |
Output is correct |
42 |
Correct |
30 ms |
12408 KB |
Output is correct |
43 |
Correct |
46 ms |
12280 KB |
Output is correct |
44 |
Correct |
79 ms |
12280 KB |
Output is correct |
45 |
Correct |
145 ms |
12280 KB |
Output is correct |
46 |
Correct |
164 ms |
12280 KB |
Output is correct |
47 |
Correct |
366 ms |
12280 KB |
Output is correct |
48 |
Correct |
437 ms |
12408 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
12024 KB |
Output is correct |
2 |
Correct |
13 ms |
12152 KB |
Output is correct |
3 |
Correct |
13 ms |
12152 KB |
Output is correct |
4 |
Correct |
12 ms |
12152 KB |
Output is correct |
5 |
Correct |
12 ms |
12024 KB |
Output is correct |
6 |
Correct |
10 ms |
12024 KB |
Output is correct |
7 |
Correct |
10 ms |
12024 KB |
Output is correct |
8 |
Correct |
11 ms |
12024 KB |
Output is correct |
9 |
Correct |
12 ms |
12152 KB |
Output is correct |
10 |
Correct |
10 ms |
12024 KB |
Output is correct |
11 |
Correct |
12 ms |
12152 KB |
Output is correct |
12 |
Correct |
10 ms |
12152 KB |
Output is correct |
13 |
Correct |
10 ms |
12152 KB |
Output is correct |
14 |
Correct |
10 ms |
12152 KB |
Output is correct |
15 |
Correct |
10 ms |
12152 KB |
Output is correct |
16 |
Correct |
10 ms |
12152 KB |
Output is correct |
17 |
Correct |
10 ms |
12152 KB |
Output is correct |
18 |
Correct |
10 ms |
12152 KB |
Output is correct |
19 |
Correct |
10 ms |
12152 KB |
Output is correct |
20 |
Correct |
10 ms |
12024 KB |
Output is correct |
21 |
Correct |
9 ms |
12028 KB |
Output is correct |
22 |
Correct |
10 ms |
12024 KB |
Output is correct |
23 |
Correct |
10 ms |
12024 KB |
Output is correct |
24 |
Correct |
10 ms |
12152 KB |
Output is correct |
25 |
Correct |
295 ms |
12536 KB |
Output is correct |
26 |
Correct |
298 ms |
12408 KB |
Output is correct |
27 |
Correct |
300 ms |
12536 KB |
Output is correct |
28 |
Correct |
296 ms |
12536 KB |
Output is correct |
29 |
Correct |
346 ms |
12516 KB |
Output is correct |
30 |
Correct |
381 ms |
12536 KB |
Output is correct |
31 |
Correct |
365 ms |
12508 KB |
Output is correct |
32 |
Correct |
372 ms |
12664 KB |
Output is correct |
33 |
Correct |
15 ms |
12536 KB |
Output is correct |
34 |
Correct |
14 ms |
12540 KB |
Output is correct |
35 |
Correct |
14 ms |
12536 KB |
Output is correct |
36 |
Correct |
15 ms |
12636 KB |
Output is correct |
37 |
Correct |
13 ms |
12636 KB |
Output is correct |
38 |
Correct |
12 ms |
12664 KB |
Output is correct |
39 |
Correct |
13 ms |
12408 KB |
Output is correct |
40 |
Correct |
15 ms |
12408 KB |
Output is correct |
41 |
Correct |
20 ms |
12280 KB |
Output is correct |
42 |
Correct |
30 ms |
12408 KB |
Output is correct |
43 |
Correct |
46 ms |
12280 KB |
Output is correct |
44 |
Correct |
79 ms |
12280 KB |
Output is correct |
45 |
Correct |
145 ms |
12280 KB |
Output is correct |
46 |
Correct |
164 ms |
12280 KB |
Output is correct |
47 |
Correct |
366 ms |
12280 KB |
Output is correct |
48 |
Correct |
437 ms |
12408 KB |
Output is correct |
49 |
Execution timed out |
2056 ms |
58516 KB |
Time limit exceeded |
50 |
Halted |
0 ms |
0 KB |
- |