#include <bits/stdc++.h>
#define int long long
using namespace std;
const int Nmax=110;
int N, mn=Nmax, R, D[Nmax], P[Nmax];
vector<int> adj[Nmax];
int DFS(int curr, int prev) {
int ret=D[curr];
for(int next:adj[curr]) if(next!=prev) P[next]=curr, D[next]=D[curr]+1, ret=max(ret, DFS(next, curr));
return ret;
}
signed main() {
ios_base::sync_with_stdio(0); cin.tie(0);
cin>>N;
// assert(N==100);
for(int i=1; i<N; i++) {
int u, v; cin>>u>>v;
adj[u].push_back(v), adj[v].push_back(u);
}
for(int i=0; i<N; i++) {
D[i]=0;
int tmp=DFS(i, -1);
if(tmp<mn) mn=tmp, R=i;
}
D[R]=0, DFS(R, -1);
cout<<mn+1<<"\n";
for(int i=0; i<N; i++) {
int x=i;
for(int j=mn; j>=1; j--) {
if(D[x]==j) x=P[x];
cout<<x<<" ";
}
cout<<R<<"\n";
}
for(int i=0; i<N; i++) {
int x=i;
for(int j=mn; j>=1; j--) {
if(D[x]==j) x=P[x];
cout<<x<<" ";
}
cout<<R<<"\n";
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
344 KB |
Cannot move |
2 |
Halted |
0 ms |
0 KB |
- |