#include <bits/stdc++.h>
using namespace std;
#define int ll
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<double> vd;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<pi> vp;
typedef vector<pl> vpl;
const int maxn = 5005;
vi e[maxn], d(maxn);
void dfs(int x, int st){
d[x] = 0;
for (int i : e[x]){
if (i != st){
dfs(i,x);
d[x] = max(d[x], d[i]);
}
}
++d[x];
}
int sol, cnt;
void calc(int x, int st=0, int dij=0, int ds=0){
int len = e[x].size();
if (len == 1 && st){
int res =ds*dij;
if (sol==res)
++cnt;
if (sol < res){
sol =res;
cnt=1;
}
}
int m = 0, y = 0;
for (int i : e[x]){
if (i == st) continue;
if (d[i] >= m){
swap(m,y);
m=d[i];
} else if (d[i] >=y){
y=d[i];
}
}
for (int i : e[x]){
if (i == st) continue;
if (m == d[i])
calc(i,x,dij+1,max(ds,y));
else
calc(i,x,dij+1,max(ds,m));
}
}
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
cerr.tie(nullptr);
int n;
cin >> n;
for (int i = 1; i < n; ++i){
int u, v;
cin >> u >> v;
e[u].push_back(v);
e[v].push_back(u);
}
int tt = 0;
for (int i = 1; i <= n; ++i){
int len = e[i].size();
tt += (len == 1);
}
if (tt == 2) return cout << "0 1\n", 0;
for (int i = 1; i <= n; ++i){
int len = e[i].size();
if (len > 1) continue;
dfs(i,i);
calc(i);
}
cout << sol << ' ' << cnt/2 << '\n';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
492 KB |
Output is correct |
2 |
Correct |
1 ms |
492 KB |
Output is correct |
3 |
Correct |
1 ms |
492 KB |
Output is correct |
4 |
Correct |
1 ms |
492 KB |
Output is correct |
5 |
Correct |
1 ms |
492 KB |
Output is correct |
6 |
Correct |
1 ms |
492 KB |
Output is correct |
7 |
Correct |
1 ms |
492 KB |
Output is correct |
8 |
Correct |
1 ms |
492 KB |
Output is correct |
9 |
Correct |
1 ms |
492 KB |
Output is correct |
10 |
Correct |
1 ms |
492 KB |
Output is correct |
11 |
Correct |
1 ms |
492 KB |
Output is correct |
12 |
Correct |
1 ms |
492 KB |
Output is correct |
13 |
Correct |
1 ms |
492 KB |
Output is correct |
14 |
Correct |
1 ms |
492 KB |
Output is correct |
15 |
Correct |
1 ms |
492 KB |
Output is correct |
16 |
Correct |
1 ms |
492 KB |
Output is correct |
17 |
Correct |
1 ms |
492 KB |
Output is correct |
18 |
Correct |
1 ms |
492 KB |
Output is correct |
19 |
Correct |
1 ms |
492 KB |
Output is correct |
20 |
Correct |
1 ms |
492 KB |
Output is correct |
21 |
Correct |
1 ms |
492 KB |
Output is correct |
22 |
Correct |
1 ms |
492 KB |
Output is correct |
23 |
Correct |
1 ms |
508 KB |
Output is correct |
24 |
Correct |
1 ms |
492 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
492 KB |
Output is correct |
2 |
Correct |
1 ms |
492 KB |
Output is correct |
3 |
Correct |
1 ms |
492 KB |
Output is correct |
4 |
Correct |
1 ms |
492 KB |
Output is correct |
5 |
Correct |
1 ms |
492 KB |
Output is correct |
6 |
Correct |
1 ms |
492 KB |
Output is correct |
7 |
Correct |
1 ms |
492 KB |
Output is correct |
8 |
Correct |
1 ms |
492 KB |
Output is correct |
9 |
Correct |
1 ms |
492 KB |
Output is correct |
10 |
Correct |
1 ms |
492 KB |
Output is correct |
11 |
Correct |
1 ms |
492 KB |
Output is correct |
12 |
Correct |
1 ms |
492 KB |
Output is correct |
13 |
Correct |
1 ms |
492 KB |
Output is correct |
14 |
Correct |
1 ms |
492 KB |
Output is correct |
15 |
Correct |
1 ms |
492 KB |
Output is correct |
16 |
Correct |
1 ms |
492 KB |
Output is correct |
17 |
Correct |
1 ms |
492 KB |
Output is correct |
18 |
Correct |
1 ms |
492 KB |
Output is correct |
19 |
Correct |
1 ms |
492 KB |
Output is correct |
20 |
Correct |
1 ms |
492 KB |
Output is correct |
21 |
Correct |
1 ms |
492 KB |
Output is correct |
22 |
Correct |
1 ms |
492 KB |
Output is correct |
23 |
Correct |
1 ms |
508 KB |
Output is correct |
24 |
Correct |
1 ms |
492 KB |
Output is correct |
25 |
Correct |
240 ms |
896 KB |
Output is correct |
26 |
Correct |
241 ms |
1004 KB |
Output is correct |
27 |
Correct |
236 ms |
1004 KB |
Output is correct |
28 |
Correct |
234 ms |
876 KB |
Output is correct |
29 |
Correct |
348 ms |
1004 KB |
Output is correct |
30 |
Correct |
335 ms |
1132 KB |
Output is correct |
31 |
Correct |
342 ms |
1000 KB |
Output is correct |
32 |
Correct |
338 ms |
1004 KB |
Output is correct |
33 |
Correct |
4 ms |
1004 KB |
Output is correct |
34 |
Correct |
4 ms |
1004 KB |
Output is correct |
35 |
Correct |
4 ms |
1004 KB |
Output is correct |
36 |
Correct |
4 ms |
1004 KB |
Output is correct |
37 |
Correct |
2 ms |
748 KB |
Output is correct |
38 |
Correct |
2 ms |
748 KB |
Output is correct |
39 |
Correct |
4 ms |
876 KB |
Output is correct |
40 |
Correct |
5 ms |
748 KB |
Output is correct |
41 |
Correct |
8 ms |
748 KB |
Output is correct |
42 |
Correct |
16 ms |
748 KB |
Output is correct |
43 |
Correct |
28 ms |
748 KB |
Output is correct |
44 |
Correct |
52 ms |
748 KB |
Output is correct |
45 |
Correct |
114 ms |
748 KB |
Output is correct |
46 |
Correct |
157 ms |
748 KB |
Output is correct |
47 |
Correct |
381 ms |
748 KB |
Output is correct |
48 |
Correct |
552 ms |
748 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
492 KB |
Output is correct |
2 |
Correct |
1 ms |
492 KB |
Output is correct |
3 |
Correct |
1 ms |
492 KB |
Output is correct |
4 |
Correct |
1 ms |
492 KB |
Output is correct |
5 |
Correct |
1 ms |
492 KB |
Output is correct |
6 |
Correct |
1 ms |
492 KB |
Output is correct |
7 |
Correct |
1 ms |
492 KB |
Output is correct |
8 |
Correct |
1 ms |
492 KB |
Output is correct |
9 |
Correct |
1 ms |
492 KB |
Output is correct |
10 |
Correct |
1 ms |
492 KB |
Output is correct |
11 |
Correct |
1 ms |
492 KB |
Output is correct |
12 |
Correct |
1 ms |
492 KB |
Output is correct |
13 |
Correct |
1 ms |
492 KB |
Output is correct |
14 |
Correct |
1 ms |
492 KB |
Output is correct |
15 |
Correct |
1 ms |
492 KB |
Output is correct |
16 |
Correct |
1 ms |
492 KB |
Output is correct |
17 |
Correct |
1 ms |
492 KB |
Output is correct |
18 |
Correct |
1 ms |
492 KB |
Output is correct |
19 |
Correct |
1 ms |
492 KB |
Output is correct |
20 |
Correct |
1 ms |
492 KB |
Output is correct |
21 |
Correct |
1 ms |
492 KB |
Output is correct |
22 |
Correct |
1 ms |
492 KB |
Output is correct |
23 |
Correct |
1 ms |
508 KB |
Output is correct |
24 |
Correct |
1 ms |
492 KB |
Output is correct |
25 |
Correct |
240 ms |
896 KB |
Output is correct |
26 |
Correct |
241 ms |
1004 KB |
Output is correct |
27 |
Correct |
236 ms |
1004 KB |
Output is correct |
28 |
Correct |
234 ms |
876 KB |
Output is correct |
29 |
Correct |
348 ms |
1004 KB |
Output is correct |
30 |
Correct |
335 ms |
1132 KB |
Output is correct |
31 |
Correct |
342 ms |
1000 KB |
Output is correct |
32 |
Correct |
338 ms |
1004 KB |
Output is correct |
33 |
Correct |
4 ms |
1004 KB |
Output is correct |
34 |
Correct |
4 ms |
1004 KB |
Output is correct |
35 |
Correct |
4 ms |
1004 KB |
Output is correct |
36 |
Correct |
4 ms |
1004 KB |
Output is correct |
37 |
Correct |
2 ms |
748 KB |
Output is correct |
38 |
Correct |
2 ms |
748 KB |
Output is correct |
39 |
Correct |
4 ms |
876 KB |
Output is correct |
40 |
Correct |
5 ms |
748 KB |
Output is correct |
41 |
Correct |
8 ms |
748 KB |
Output is correct |
42 |
Correct |
16 ms |
748 KB |
Output is correct |
43 |
Correct |
28 ms |
748 KB |
Output is correct |
44 |
Correct |
52 ms |
748 KB |
Output is correct |
45 |
Correct |
114 ms |
748 KB |
Output is correct |
46 |
Correct |
157 ms |
748 KB |
Output is correct |
47 |
Correct |
381 ms |
748 KB |
Output is correct |
48 |
Correct |
552 ms |
748 KB |
Output is correct |
49 |
Runtime error |
1 ms |
876 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
50 |
Halted |
0 ms |
0 KB |
- |