#include <iostream>
#include <vector>
#include <climits>
using namespace std;
void dfs(int cur,int prev,vector<vector<int>> &child,vector<vector<int>> &g) {
for(auto u : g[cur]) {
if(u==prev) continue;
child[cur].push_back(u);
dfs(u,cur,child,g);
}
}
void sw(int x,int y, vector<int> &perm) {
swap(perm[x],perm[y]);
}
int dfs2(int cur,int per,vector<vector<int>> &child,vector<int> &perm) {
int res = 0;
for (int i :child[cur]) {
res+=dfs2(i,cur,child,perm);
}
if(perm[cur]==cur) {sw(per,cur,perm); res+=2;}
return res;
}
int main() {
int n; cin>>n;
vector<vector<int>> g(n);
for (int i = 0; i < n-1; ++i) {
int x,y; cin>>x>>y; x--; y--;
g[x].push_back(y);
g[y].push_back(x);
}
vector<vector<int>> c(n);
vector<int> perm(n);
int root=0;
for (int i = 0; i < n; ++i) {
perm[i]=i;
if(g[i].size()==1) root = i;
}
dfs(root,-1,c,g);
cout<< dfs2(root,c[root][0],c,perm) <<" "<<1<<endl;
for (int i = 0; i < n; ++i) {
cout<<perm[i]<<" ";
}
cout<<endl;
for (int i = 0; i < n; ++i) {
cout<<perm[i]<<" ";
}
cout<<endl;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
336 KB |
Integer parameter [name=vi] equals to 0, violates the range [1, 4] |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
336 KB |
Integer parameter [name=vi] equals to 0, violates the range [1, 256] |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
336 KB |
Integer parameter [name=vi] equals to 0, violates the range [1, 4] |
2 |
Halted |
0 ms |
0 KB |
- |