#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define debug(...)
#endif
using ll=long long;
using pii=array<int,2>;
using tii=array<int,3>;
using ti4=array<int,4>;
const int N=105;
int n,p[N],dep[N],c[N];
vector<int> L[N];
vector<int> g[N],ans[2][N];
void dfs(int u){
L[dep[u]].push_back(u);
for(int v: g[u]) if(p[u]!=v){
p[v]=u;
dep[v]=dep[u]+1;
dfs(v);
}
}
int main(){
ios::sync_with_stdio(false); cin.tie(0);
cin>>n;
for(int u,v,i=1;i<n;i++){
cin>>u>>v;
u++; v++;
g[u].push_back(v);
g[v].push_back(u);
}
dep[1]=1;
dfs(1);
for(int i=1;i<=n;i++) c[i]=i;
for(int d=n;d>=1;d--) if(L[d].size()){
for(int u=1;u<=n;u++){
int v=c[u];
if(dep[u]<=d){
ans[0][u].push_back(v);
ans[0][u].push_back(v);
ans[1][u].push_back(v);
ans[1][u].push_back(v);
} else{
ans[0][u].push_back(p[v]);
ans[0][u].push_back(p[v]);
ans[1][u].push_back(v);
ans[1][u].push_back(p[v]);
c[u]=p[v];
}
}
}
cout<<ans[0][1].size()<<"\n";
for(int i=1;i<=n;i++){
for(int x: ans[0][i]) cout<<x-1<<" ";
cout<<"\n";
}
for(int i=1;i<=n;i++){
for(int x: ans[1][i]) cout<<x-1<<" ";
cout<<"\n";
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Partially correct |
2 ms |
604 KB |
Partially correct |
2 |
Partially correct |
1 ms |
604 KB |
Partially correct |
3 |
Partially correct |
2 ms |
604 KB |
Partially correct |
4 |
Partially correct |
1 ms |
604 KB |
Partially correct |
5 |
Partially correct |
1 ms |
604 KB |
Partially correct |
6 |
Partially correct |
1 ms |
604 KB |
Partially correct |
7 |
Correct |
0 ms |
344 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Partially correct |
1 ms |
348 KB |
Partially correct |
17 |
Partially correct |
0 ms |
348 KB |
Partially correct |
18 |
Partially correct |
0 ms |
348 KB |
Partially correct |
19 |
Partially correct |
1 ms |
348 KB |
Partially correct |
20 |
Partially correct |
1 ms |
348 KB |
Partially correct |
21 |
Partially correct |
0 ms |
348 KB |
Partially correct |
22 |
Partially correct |
0 ms |
348 KB |
Partially correct |
23 |
Partially correct |
1 ms |
348 KB |
Partially correct |
24 |
Partially correct |
1 ms |
604 KB |
Partially correct |
25 |
Partially correct |
1 ms |
604 KB |
Partially correct |