# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
969438 |
2024-04-25T07:06:15 Z |
vjudge1 |
Cities (BOI16_cities) |
C++17 |
|
4 ms |
5212 KB |
#include<iostream>
#include<vector>
using namespace std;
int parent[100007];
int ans;
int u,v;
vector<int> vec[100007];
void dfs(int x,int ori)
{
// cout << x << ' ';
for(auto i:vec[x]){
if(i==ori) continue;
dfs(i,x);
}
if(parent[x]==x){
ans+=2;
if(ori) swap(parent[x],parent[ori]);
else {
swap(parent[x],parent[vec[x][0]]);
// cout << x << ' ' << vec[x][0];
}
}
}
int main()
{
int n; cin >> n;
for(int i=1;i<n;++i){
cin >> u >> v;
vec[u].push_back(v);
vec[v].push_back(u);
}
for(int i=1;i<=n;++i) parent[i]=i;
dfs(1,0);
// cout << '\n';
cout << ans << endl;
for(int i=1;i<=n;i++) cout << parent[i] << " ";
}
/*
5
1 2
2 3
3 4
4 5
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
2652 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
4 ms |
5212 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
3 ms |
5212 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
3 ms |
5208 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
3 ms |
5212 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |