#include <bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define ub upper_bound
#define lb lower_bound
#define ll long long
#define ld long double
#define pii pair<int, int>
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(),x.rend()
#define prc(n) fixed << setprecision(n)
#define fastios ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pi acos(-1);
const int inf = 1e9+7;
const int N = 105;
vector<vector<int>> edges(N);
int dis[N][N], cur, goal;
int used[N];
int ds[N];
int ans[N * N];
void dfs(int d, int u, int prev){
dis[cur][u] = d;
for(auto x:edges[u]){
if(x == prev) continue;
dfs(d+1, x, u);
}
}
int dfs1(int u, int prev){
if(u == goal){
used[u] = 1;
return 1;
}
int mx = 0;
for(auto x:edges[u]){
if(x == prev) continue;
mx = max(dfs1(x, u), mx);
}
used[u] = mx;
return mx;
}
void dfs2(int d, int u, int prev){
if(used[u]){
int next = -1;
for(auto x:edges[u]){
if(x == prev) continue;
else if(used[x]) next = x;
else dfs2(d+1, x, u);
}
if(next == -1) return;
dfs2(d, next, u);
}
else{
ds[u] = d;
for(auto x:edges[u]){
if(x == prev) continue;
dfs2(d+1, x, u);
}
}
}
void solve(){
fastios
int n;
cin>>n;
vector<int>last;
for(int i=1;i<n;i++){
int a, b;
cin>>a>>b;
edges[a].pb(b);
edges[b].pb(a);
}
for(int i=1;i<=n;i++){
cur = i;
dfs(0, i, -1);
if(sz(edges[i]) == 1) last.pb(i);
}
for(int i=0;i<sz(last);i++){
for(int j=i+1;j<sz(last);j++){
cur = last[i], goal = last[j];
dfs1(cur, -1);
dfs2(0, cur, -1);
int mx = 0;
for(int l=1; l<=n; l++){
mx = max(mx, ds[l]);
}
ans[mx * dis[cur][goal]]++;
memset(ds, 0, sizeof(ds));
memset(used, 0, sizeof(used));
}
}
int mx, nm;
for(int i=(N*N); i>=0; i--){
if(ans[i]){
mx = i;
nm = ans[i];
break;
}
}
cout<<mx<<" "<<nm<<"\n";
return;
}
int main(){
fastios
int t = 1;
//cin>>t;
while(t--) solve();
return 0;
}
Compilation message
road.cpp: In function 'void solve()':
road.cpp:110:21: warning: 'nm' may be used uninitialized in this function [-Wmaybe-uninitialized]
110 | cout<<mx<<" "<<nm<<"\n";
| ^~~~
road.cpp:110:12: warning: 'mx' may be used uninitialized in this function [-Wmaybe-uninitialized]
110 | cout<<mx<<" "<<nm<<"\n";
| ^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
2 ms |
364 KB |
Output is correct |
10 |
Correct |
2 ms |
492 KB |
Output is correct |
11 |
Correct |
4 ms |
512 KB |
Output is correct |
12 |
Correct |
3 ms |
364 KB |
Output is correct |
13 |
Correct |
3 ms |
364 KB |
Output is correct |
14 |
Correct |
3 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
2 ms |
364 KB |
Output is correct |
17 |
Correct |
1 ms |
364 KB |
Output is correct |
18 |
Correct |
1 ms |
364 KB |
Output is correct |
19 |
Correct |
1 ms |
364 KB |
Output is correct |
20 |
Correct |
1 ms |
384 KB |
Output is correct |
21 |
Correct |
1 ms |
364 KB |
Output is correct |
22 |
Correct |
1 ms |
364 KB |
Output is correct |
23 |
Correct |
1 ms |
364 KB |
Output is correct |
24 |
Correct |
9 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
2 ms |
364 KB |
Output is correct |
10 |
Correct |
2 ms |
492 KB |
Output is correct |
11 |
Correct |
4 ms |
512 KB |
Output is correct |
12 |
Correct |
3 ms |
364 KB |
Output is correct |
13 |
Correct |
3 ms |
364 KB |
Output is correct |
14 |
Correct |
3 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
2 ms |
364 KB |
Output is correct |
17 |
Correct |
1 ms |
364 KB |
Output is correct |
18 |
Correct |
1 ms |
364 KB |
Output is correct |
19 |
Correct |
1 ms |
364 KB |
Output is correct |
20 |
Correct |
1 ms |
384 KB |
Output is correct |
21 |
Correct |
1 ms |
364 KB |
Output is correct |
22 |
Correct |
1 ms |
364 KB |
Output is correct |
23 |
Correct |
1 ms |
364 KB |
Output is correct |
24 |
Correct |
9 ms |
364 KB |
Output is correct |
25 |
Runtime error |
1 ms |
620 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
26 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
2 ms |
364 KB |
Output is correct |
10 |
Correct |
2 ms |
492 KB |
Output is correct |
11 |
Correct |
4 ms |
512 KB |
Output is correct |
12 |
Correct |
3 ms |
364 KB |
Output is correct |
13 |
Correct |
3 ms |
364 KB |
Output is correct |
14 |
Correct |
3 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
2 ms |
364 KB |
Output is correct |
17 |
Correct |
1 ms |
364 KB |
Output is correct |
18 |
Correct |
1 ms |
364 KB |
Output is correct |
19 |
Correct |
1 ms |
364 KB |
Output is correct |
20 |
Correct |
1 ms |
384 KB |
Output is correct |
21 |
Correct |
1 ms |
364 KB |
Output is correct |
22 |
Correct |
1 ms |
364 KB |
Output is correct |
23 |
Correct |
1 ms |
364 KB |
Output is correct |
24 |
Correct |
9 ms |
364 KB |
Output is correct |
25 |
Runtime error |
1 ms |
620 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
26 |
Halted |
0 ms |
0 KB |
- |