#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define int long long
#define endl "\n"
int mod=1e7+9;
const int N=5005;//2e5+5;
template<class x>
using ordered_multiset = tree<x, null_type,less_equal<x>, rb_tree_tag,tree_order_statistics_node_update>;
int n,ans,cnt;
int dis[N];
pair<int,int> lvs[N];
vector<int> v[N];
void cldis(int i,int par,int d) {
dis[i]=0;
for (int j:v[i]) {
if (j!=par) {
cldis(j,i,d+1);
dis[i]=max(dis[i],dis[j]);
}
}
dis[i]++;
}
void dfs(int i,int par,int lvl,int h) {
if (v[i].size()==1 && par!=0) {
int tmp=lvl*h;
if (tmp==ans) cnt++;
else if (tmp>ans) {ans=tmp; cnt=1;}
return;
}
int mx1=0,mx2=0;
for (int j:v[i]) {
if (j!=par) {
if (dis[j]>=mx1) {mx2=mx1; mx1=dis[j];}
else if (dis[j]<mx1 && dis[j]>mx2) mx2=dis[j];
}
}
for (int j:v[i]) {
int gg;
if (j!=par) {
if (dis[j]==mx1) gg=mx2;
else gg=mx1;
dfs(j,i,lvl+1,max(gg,h));
}
}
}
signed main() {
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
cin>>n;
for (int i=1;i<n;i++) {
int a,b; cin>>a>>b;
v[a].push_back(b);
v[b].push_back(a);
}
for (int i=1;i<=n;i++) {
if (v[i].size()>1) continue;
cldis(i,0,0);
dfs(i,0,0,0);
}
cout<<ans<<' '<<cnt/2;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
440 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
444 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
428 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
468 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
440 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
440 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
444 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
428 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
468 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
440 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
191 ms |
884 KB |
Output is correct |
26 |
Correct |
197 ms |
888 KB |
Output is correct |
27 |
Correct |
203 ms |
876 KB |
Output is correct |
28 |
Correct |
193 ms |
852 KB |
Output is correct |
29 |
Correct |
254 ms |
900 KB |
Output is correct |
30 |
Correct |
287 ms |
900 KB |
Output is correct |
31 |
Correct |
232 ms |
908 KB |
Output is correct |
32 |
Correct |
251 ms |
852 KB |
Output is correct |
33 |
Correct |
4 ms |
964 KB |
Output is correct |
34 |
Correct |
4 ms |
988 KB |
Output is correct |
35 |
Correct |
4 ms |
980 KB |
Output is correct |
36 |
Correct |
5 ms |
972 KB |
Output is correct |
37 |
Correct |
3 ms |
968 KB |
Output is correct |
38 |
Correct |
3 ms |
980 KB |
Output is correct |
39 |
Correct |
3 ms |
724 KB |
Output is correct |
40 |
Correct |
5 ms |
712 KB |
Output is correct |
41 |
Correct |
6 ms |
724 KB |
Output is correct |
42 |
Correct |
13 ms |
596 KB |
Output is correct |
43 |
Correct |
21 ms |
584 KB |
Output is correct |
44 |
Correct |
42 ms |
672 KB |
Output is correct |
45 |
Correct |
92 ms |
596 KB |
Output is correct |
46 |
Correct |
116 ms |
636 KB |
Output is correct |
47 |
Correct |
260 ms |
692 KB |
Output is correct |
48 |
Correct |
322 ms |
724 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
440 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
444 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
428 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
468 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
440 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
191 ms |
884 KB |
Output is correct |
26 |
Correct |
197 ms |
888 KB |
Output is correct |
27 |
Correct |
203 ms |
876 KB |
Output is correct |
28 |
Correct |
193 ms |
852 KB |
Output is correct |
29 |
Correct |
254 ms |
900 KB |
Output is correct |
30 |
Correct |
287 ms |
900 KB |
Output is correct |
31 |
Correct |
232 ms |
908 KB |
Output is correct |
32 |
Correct |
251 ms |
852 KB |
Output is correct |
33 |
Correct |
4 ms |
964 KB |
Output is correct |
34 |
Correct |
4 ms |
988 KB |
Output is correct |
35 |
Correct |
4 ms |
980 KB |
Output is correct |
36 |
Correct |
5 ms |
972 KB |
Output is correct |
37 |
Correct |
3 ms |
968 KB |
Output is correct |
38 |
Correct |
3 ms |
980 KB |
Output is correct |
39 |
Correct |
3 ms |
724 KB |
Output is correct |
40 |
Correct |
5 ms |
712 KB |
Output is correct |
41 |
Correct |
6 ms |
724 KB |
Output is correct |
42 |
Correct |
13 ms |
596 KB |
Output is correct |
43 |
Correct |
21 ms |
584 KB |
Output is correct |
44 |
Correct |
42 ms |
672 KB |
Output is correct |
45 |
Correct |
92 ms |
596 KB |
Output is correct |
46 |
Correct |
116 ms |
636 KB |
Output is correct |
47 |
Correct |
260 ms |
692 KB |
Output is correct |
48 |
Correct |
322 ms |
724 KB |
Output is correct |
49 |
Runtime error |
1 ms |
724 KB |
Execution killed with signal 11 |
50 |
Halted |
0 ms |
0 KB |
- |