#include<iostream>
#include<algorithm>
#include<iomanip>
#include<cmath>
#include<cstring>
#include<vector>
#include<queue>
#include<stack>
#include<tuple>
#include<set>
#include<map>
#include<random>
#include<chrono>
using namespace std;
const int MAX_N=5e5+5;
int maxd[MAX_N];
int maxd2[MAX_N];
int dp[MAX_N];
vector<int>g[MAX_N];
int n;
int cnt;
int depth[MAX_N];
int ans;
void dfsdown(int u,int par)
{
for(int v:g[u])
{
if(v==par)continue;
depth[v]=depth[u]+1;
dfsdown(v,u);
if(maxd[v]+1>maxd[u])
{
maxd2[u]=maxd[u];
maxd[u]=maxd[v]+1;
}
else if(maxd[v]+1==maxd[u])
{
maxd2[u]=maxd[u];
}
}
}
void dfsup(int u,int par)
{
for(int v:g[u])
{
if(v==par)continue;
int cur=maxd[u];
if(maxd[v]+1==maxd[u])cur=maxd2[u];
dp[v]=max(dp[u],cur);
dfsup(v,u);
}
}
void solvefor(int root)
{
for(int i=1;i<=n;i++)
{
maxd[i]=0;
maxd2[i]=0;
dp[i]=0;
depth[i]=0;
}
dfsdown(root,0);
dfsup(root,0);
for(int i=1;i<=n;i++)
{
if(g[i].size()!=1 or i==root)continue;
int curhardness=depth[i]*dp[i];
if(curhardness>ans)
{
ans=curhardness;
cnt=1;
}
else if(curhardness==ans)cnt++;
}
}
signed main()
{
ios_base::sync_with_stdio(0);
cin.tie(NULL);
cout.tie(NULL);
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 i=1;i<=n;i++)
{
if(g[i].size()!=1)continue;
solvefor(i);
}
cout<<ans<<" "<<cnt/2<<"\n";
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
18776 KB |
Output is correct |
2 |
Correct |
3 ms |
18776 KB |
Output is correct |
3 |
Correct |
2 ms |
18780 KB |
Output is correct |
4 |
Correct |
2 ms |
18872 KB |
Output is correct |
5 |
Correct |
3 ms |
18928 KB |
Output is correct |
6 |
Correct |
2 ms |
18780 KB |
Output is correct |
7 |
Correct |
2 ms |
18780 KB |
Output is correct |
8 |
Correct |
2 ms |
18780 KB |
Output is correct |
9 |
Correct |
2 ms |
18780 KB |
Output is correct |
10 |
Correct |
2 ms |
18780 KB |
Output is correct |
11 |
Correct |
3 ms |
18780 KB |
Output is correct |
12 |
Correct |
3 ms |
18780 KB |
Output is correct |
13 |
Correct |
3 ms |
18780 KB |
Output is correct |
14 |
Correct |
2 ms |
18780 KB |
Output is correct |
15 |
Correct |
2 ms |
18780 KB |
Output is correct |
16 |
Correct |
2 ms |
18780 KB |
Output is correct |
17 |
Correct |
2 ms |
18780 KB |
Output is correct |
18 |
Correct |
3 ms |
18780 KB |
Output is correct |
19 |
Correct |
2 ms |
18780 KB |
Output is correct |
20 |
Correct |
3 ms |
18776 KB |
Output is correct |
21 |
Correct |
3 ms |
18780 KB |
Output is correct |
22 |
Correct |
2 ms |
18780 KB |
Output is correct |
23 |
Correct |
3 ms |
18780 KB |
Output is correct |
24 |
Correct |
2 ms |
18780 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
18776 KB |
Output is correct |
2 |
Correct |
3 ms |
18776 KB |
Output is correct |
3 |
Correct |
2 ms |
18780 KB |
Output is correct |
4 |
Correct |
2 ms |
18872 KB |
Output is correct |
5 |
Correct |
3 ms |
18928 KB |
Output is correct |
6 |
Correct |
2 ms |
18780 KB |
Output is correct |
7 |
Correct |
2 ms |
18780 KB |
Output is correct |
8 |
Correct |
2 ms |
18780 KB |
Output is correct |
9 |
Correct |
2 ms |
18780 KB |
Output is correct |
10 |
Correct |
2 ms |
18780 KB |
Output is correct |
11 |
Correct |
3 ms |
18780 KB |
Output is correct |
12 |
Correct |
3 ms |
18780 KB |
Output is correct |
13 |
Correct |
3 ms |
18780 KB |
Output is correct |
14 |
Correct |
2 ms |
18780 KB |
Output is correct |
15 |
Correct |
2 ms |
18780 KB |
Output is correct |
16 |
Correct |
2 ms |
18780 KB |
Output is correct |
17 |
Correct |
2 ms |
18780 KB |
Output is correct |
18 |
Correct |
3 ms |
18780 KB |
Output is correct |
19 |
Correct |
2 ms |
18780 KB |
Output is correct |
20 |
Correct |
3 ms |
18776 KB |
Output is correct |
21 |
Correct |
3 ms |
18780 KB |
Output is correct |
22 |
Correct |
2 ms |
18780 KB |
Output is correct |
23 |
Correct |
3 ms |
18780 KB |
Output is correct |
24 |
Correct |
2 ms |
18780 KB |
Output is correct |
25 |
Correct |
121 ms |
19292 KB |
Output is correct |
26 |
Correct |
125 ms |
19288 KB |
Output is correct |
27 |
Correct |
130 ms |
19292 KB |
Output is correct |
28 |
Correct |
130 ms |
19288 KB |
Output is correct |
29 |
Correct |
187 ms |
19288 KB |
Output is correct |
30 |
Correct |
197 ms |
19540 KB |
Output is correct |
31 |
Correct |
195 ms |
19348 KB |
Output is correct |
32 |
Correct |
203 ms |
19292 KB |
Output is correct |
33 |
Correct |
5 ms |
19292 KB |
Output is correct |
34 |
Correct |
4 ms |
19292 KB |
Output is correct |
35 |
Correct |
5 ms |
19292 KB |
Output is correct |
36 |
Correct |
5 ms |
19292 KB |
Output is correct |
37 |
Correct |
4 ms |
19396 KB |
Output is correct |
38 |
Correct |
4 ms |
19540 KB |
Output is correct |
39 |
Correct |
5 ms |
19288 KB |
Output is correct |
40 |
Correct |
6 ms |
19036 KB |
Output is correct |
41 |
Correct |
6 ms |
19188 KB |
Output is correct |
42 |
Correct |
10 ms |
19036 KB |
Output is correct |
43 |
Correct |
15 ms |
19036 KB |
Output is correct |
44 |
Correct |
27 ms |
19036 KB |
Output is correct |
45 |
Correct |
53 ms |
19036 KB |
Output is correct |
46 |
Correct |
77 ms |
19292 KB |
Output is correct |
47 |
Correct |
172 ms |
19036 KB |
Output is correct |
48 |
Correct |
217 ms |
19036 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
18776 KB |
Output is correct |
2 |
Correct |
3 ms |
18776 KB |
Output is correct |
3 |
Correct |
2 ms |
18780 KB |
Output is correct |
4 |
Correct |
2 ms |
18872 KB |
Output is correct |
5 |
Correct |
3 ms |
18928 KB |
Output is correct |
6 |
Correct |
2 ms |
18780 KB |
Output is correct |
7 |
Correct |
2 ms |
18780 KB |
Output is correct |
8 |
Correct |
2 ms |
18780 KB |
Output is correct |
9 |
Correct |
2 ms |
18780 KB |
Output is correct |
10 |
Correct |
2 ms |
18780 KB |
Output is correct |
11 |
Correct |
3 ms |
18780 KB |
Output is correct |
12 |
Correct |
3 ms |
18780 KB |
Output is correct |
13 |
Correct |
3 ms |
18780 KB |
Output is correct |
14 |
Correct |
2 ms |
18780 KB |
Output is correct |
15 |
Correct |
2 ms |
18780 KB |
Output is correct |
16 |
Correct |
2 ms |
18780 KB |
Output is correct |
17 |
Correct |
2 ms |
18780 KB |
Output is correct |
18 |
Correct |
3 ms |
18780 KB |
Output is correct |
19 |
Correct |
2 ms |
18780 KB |
Output is correct |
20 |
Correct |
3 ms |
18776 KB |
Output is correct |
21 |
Correct |
3 ms |
18780 KB |
Output is correct |
22 |
Correct |
2 ms |
18780 KB |
Output is correct |
23 |
Correct |
3 ms |
18780 KB |
Output is correct |
24 |
Correct |
2 ms |
18780 KB |
Output is correct |
25 |
Correct |
121 ms |
19292 KB |
Output is correct |
26 |
Correct |
125 ms |
19288 KB |
Output is correct |
27 |
Correct |
130 ms |
19292 KB |
Output is correct |
28 |
Correct |
130 ms |
19288 KB |
Output is correct |
29 |
Correct |
187 ms |
19288 KB |
Output is correct |
30 |
Correct |
197 ms |
19540 KB |
Output is correct |
31 |
Correct |
195 ms |
19348 KB |
Output is correct |
32 |
Correct |
203 ms |
19292 KB |
Output is correct |
33 |
Correct |
5 ms |
19292 KB |
Output is correct |
34 |
Correct |
4 ms |
19292 KB |
Output is correct |
35 |
Correct |
5 ms |
19292 KB |
Output is correct |
36 |
Correct |
5 ms |
19292 KB |
Output is correct |
37 |
Correct |
4 ms |
19396 KB |
Output is correct |
38 |
Correct |
4 ms |
19540 KB |
Output is correct |
39 |
Correct |
5 ms |
19288 KB |
Output is correct |
40 |
Correct |
6 ms |
19036 KB |
Output is correct |
41 |
Correct |
6 ms |
19188 KB |
Output is correct |
42 |
Correct |
10 ms |
19036 KB |
Output is correct |
43 |
Correct |
15 ms |
19036 KB |
Output is correct |
44 |
Correct |
27 ms |
19036 KB |
Output is correct |
45 |
Correct |
53 ms |
19036 KB |
Output is correct |
46 |
Correct |
77 ms |
19292 KB |
Output is correct |
47 |
Correct |
172 ms |
19036 KB |
Output is correct |
48 |
Correct |
217 ms |
19036 KB |
Output is correct |
49 |
Execution timed out |
2012 ms |
62528 KB |
Time limit exceeded |
50 |
Halted |
0 ms |
0 KB |
- |