#include<bits/stdc++.h>
using namespace std;
int n,dp[5005],ans,cnt,id[5005],root,dp2[5005];
bool leaf[5005];
vector<int>g[5005];
void build(int v,int p){
dp[v]=0;
dp2[v]=0;
for(int to:g[v])if(to!=p){
build(to,v);
if(dp[to]+1>dp[v]){
dp[v]=dp[to]+1;
id[v]=to;
}
}
for(int to:g[v])if(to!=p&&to!=id[v])dp2[v]=max(dp2[v],dp[to]+1);
}
void dfs(int v,int p,int depth,int mx){
if(v!=root&&leaf[v]&&leaf[root]){
//cout<<root<<"-"<<v<<" "<<depth<<" "<<max(mx,dp[v])<<endl;
int tmp=depth*max(mx,dp[v]);
if(tmp>ans){
ans=tmp;
cnt=1;
}else if(tmp==ans)cnt++;
}
for(int to:g[v])if(to!=p){
if(to==id[v]){
dfs(to,v,depth+1,max(mx,dp2[v]));
}else{
dfs(to,v,depth+1,max(mx,dp[v]));
}
}
}
int main(){
scanf("%d",&n);
for(int i=1;i<n;i++){
int x,y;
scanf("%d%d",&x,&y);
g[x].push_back(y);
g[y].push_back(x);
}
for(int i=1;i<=n;i++)leaf[i]=(g[i].size()==1);
for(root=1;root<=n;root++){
if(!leaf[root])continue;
build(root,root);
dfs(root,root,0,0);
}
if(ans==0)cnt=2;
printf("%d %d",ans,(cnt>>1));
}
Compilation message
road.cpp: In function 'int main()':
road.cpp:36:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
36 | scanf("%d",&n);
| ~~~~~^~~~~~~~~
road.cpp:39:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
39 | scanf("%d%d",&x,&y);
| ~~~~~^~~~~~~~~~~~~~
# |
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 |
512 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 |
620 KB |
Output is correct |
24 |
Correct |
1 ms |
496 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 |
512 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 |
620 KB |
Output is correct |
24 |
Correct |
1 ms |
496 KB |
Output is correct |
25 |
Correct |
229 ms |
876 KB |
Output is correct |
26 |
Correct |
241 ms |
956 KB |
Output is correct |
27 |
Correct |
254 ms |
896 KB |
Output is correct |
28 |
Correct |
238 ms |
876 KB |
Output is correct |
29 |
Correct |
342 ms |
1004 KB |
Output is correct |
30 |
Correct |
335 ms |
876 KB |
Output is correct |
31 |
Correct |
352 ms |
876 KB |
Output is correct |
32 |
Correct |
331 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 |
7 ms |
1004 KB |
Output is correct |
37 |
Correct |
3 ms |
1132 KB |
Output is correct |
38 |
Correct |
3 ms |
1132 KB |
Output is correct |
39 |
Correct |
5 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 |
15 ms |
748 KB |
Output is correct |
43 |
Correct |
30 ms |
748 KB |
Output is correct |
44 |
Correct |
54 ms |
748 KB |
Output is correct |
45 |
Correct |
108 ms |
748 KB |
Output is correct |
46 |
Correct |
162 ms |
620 KB |
Output is correct |
47 |
Correct |
367 ms |
876 KB |
Output is correct |
48 |
Correct |
567 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 |
512 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 |
620 KB |
Output is correct |
24 |
Correct |
1 ms |
496 KB |
Output is correct |
25 |
Correct |
229 ms |
876 KB |
Output is correct |
26 |
Correct |
241 ms |
956 KB |
Output is correct |
27 |
Correct |
254 ms |
896 KB |
Output is correct |
28 |
Correct |
238 ms |
876 KB |
Output is correct |
29 |
Correct |
342 ms |
1004 KB |
Output is correct |
30 |
Correct |
335 ms |
876 KB |
Output is correct |
31 |
Correct |
352 ms |
876 KB |
Output is correct |
32 |
Correct |
331 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 |
7 ms |
1004 KB |
Output is correct |
37 |
Correct |
3 ms |
1132 KB |
Output is correct |
38 |
Correct |
3 ms |
1132 KB |
Output is correct |
39 |
Correct |
5 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 |
15 ms |
748 KB |
Output is correct |
43 |
Correct |
30 ms |
748 KB |
Output is correct |
44 |
Correct |
54 ms |
748 KB |
Output is correct |
45 |
Correct |
108 ms |
748 KB |
Output is correct |
46 |
Correct |
162 ms |
620 KB |
Output is correct |
47 |
Correct |
367 ms |
876 KB |
Output is correct |
48 |
Correct |
567 ms |
748 KB |
Output is correct |
49 |
Runtime error |
1 ms |
748 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
50 |
Halted |
0 ms |
0 KB |
- |