#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
using lint = long long;
using vint = vector<int>;
using pii = pair<int,int>;
const int MAX_N=105;
int n;
vint edge[MAX_N];
int pa[MAX_N];
int t=146;
vector<pii> moves[2]={
{{3,1},{13,0},{57,1}},
{{3,0},{13,1},{20,0},{37,1}}};
int dep(int v,int p,int d)
{
int mxd=d;
pa[v]=p;
for(auto v0 : edge[v])
if(v0!=p)
mxd=max(mxd,dep(v0,v,d+1));
return mxd;
}
int main()
{
ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
cin >> n;
if(n!=100)return 1;
for(int i=1;i<n;i++)
{
int u,v;
cin >> u >> v;
edge[u].push_back(v);
edge[v].push_back(u);
}
int root=0,d=dep(0,0,0);
for(int i=0;i<n;i++)
{
int cd=dep(i,i,0);
if(cd>=d)continue;
root=i;d=cd;
}
dep(root,root,0);
cout << t << '\n';
for(int k=0;k<2;k++)
{
for(int i=0;i<n;i++)
{
int v=i;
for(auto p : moves[k])
for(int j=0;j<p.first;j++)
{
if(k)cout << v << ' ';
if(p.second)v=pa[v];
cout << v << ' ';
if(!k)cout << v << ' ';
}
cout << '\n';
}
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
348 KB |
For some pair of nodes Ondrej and Edward do not meet each other |
2 |
Halted |
0 ms |
0 KB |
- |