#include<bits/stdc++.h>
using namespace std;
#ifdef DEBUG
auto& operator <<(auto& o, pair<auto, auto> p) {return o<<"{"<<p.first<<", "<<p.second<<"}";}
auto& operator <<(auto& o, auto x) {o<<"{"; for(auto v : x) o<<v<<", "; return o<<"}";}
#define debug(X) cerr<<"["#X"]: "<<X<<endl;
#else
#define debug(X) {}
#endif
vector<int> MinSolve(vector<vector<int> > graph)
{
int n = graph.size();
vector<int> result(n+1);
for(int i=0;i<n+1;i++) result[i] = i;
vector<int> par(n+1);
vector<int> deg(n+1);
queue<int> q;
function<void(int, int)> dfs = [&](int a, int fat)
{
par[a] = fat;
for(auto v : graph[a])
if(fat != v)
dfs(v, a);
deg[a] = graph[a].size();
if(a != 1 && graph[a].size() == 1) q.push(a);
};
dfs(1, -1);
while(!q.empty())
{
int a = q.front();
q.pop();
if(a == 1) continue;
if(result[a] == a)
swap(result[a], result[par[a]]), result[0]+=2;
deg[par[a]]--;
if(deg[par[a]] == 1) q.push(par[a]);
}
if(result[1] == 1)
{
result[0] += 2;
swap(result[graph[1][0]], result[1]);
}
return result;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n;
cin>>n;
vector<vector<int> > graph(n+1);
for(int i=0;i<n-1;i++)
{
int a, b;
cin>>a>>b;
graph[a].push_back(b);
graph[b].push_back(a);
}
vector<int> result = MinSolve(graph);
cout<<result[0]<<" "<<0<<"\n";
for(int i=1;i<=n;i++) cout<<result[i]<<" ";
cout<<"\n";
for(;n--;) cout<<1<<" ";
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Partially correct |
1 ms |
348 KB |
Partially correct |
2 |
Partially correct |
0 ms |
348 KB |
Partially correct |
3 |
Partially correct |
0 ms |
348 KB |
Partially correct |
4 |
Partially correct |
1 ms |
348 KB |
Partially correct |
5 |
Partially correct |
0 ms |
348 KB |
Partially correct |
6 |
Partially correct |
0 ms |
348 KB |
Partially correct |
7 |
Partially correct |
0 ms |
348 KB |
Partially correct |
8 |
Partially correct |
0 ms |
348 KB |
Partially correct |
9 |
Partially correct |
0 ms |
348 KB |
Partially correct |
10 |
Partially correct |
0 ms |
348 KB |
Partially correct |
11 |
Partially correct |
0 ms |
348 KB |
Partially correct |
12 |
Partially correct |
0 ms |
344 KB |
Partially correct |
13 |
Partially correct |
0 ms |
348 KB |
Partially correct |
14 |
Partially correct |
0 ms |
348 KB |
Partially correct |
15 |
Partially correct |
1 ms |
344 KB |
Partially correct |
16 |
Partially correct |
0 ms |
348 KB |
Partially correct |
17 |
Partially correct |
0 ms |
348 KB |
Partially correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Partially correct |
1 ms |
344 KB |
Partially correct |
2 |
Partially correct |
1 ms |
344 KB |
Partially correct |
3 |
Partially correct |
0 ms |
348 KB |
Partially correct |
4 |
Partially correct |
1 ms |
348 KB |
Partially correct |
5 |
Partially correct |
1 ms |
348 KB |
Partially correct |
6 |
Partially correct |
1 ms |
348 KB |
Partially correct |
7 |
Partially correct |
1 ms |
604 KB |
Partially correct |
8 |
Partially correct |
1 ms |
348 KB |
Partially correct |
9 |
Partially correct |
1 ms |
460 KB |
Partially correct |
10 |
Partially correct |
1 ms |
604 KB |
Partially correct |
11 |
Partially correct |
1 ms |
604 KB |
Partially correct |
12 |
Partially correct |
0 ms |
604 KB |
Partially correct |
13 |
Partially correct |
1 ms |
604 KB |
Partially correct |
14 |
Partially correct |
1 ms |
600 KB |
Partially correct |
15 |
Partially correct |
1 ms |
348 KB |
Partially correct |
16 |
Partially correct |
0 ms |
348 KB |
Partially correct |
17 |
Partially correct |
1 ms |
604 KB |
Partially correct |
18 |
Partially correct |
1 ms |
348 KB |
Partially correct |
19 |
Partially correct |
1 ms |
604 KB |
Partially correct |
20 |
Partially correct |
1 ms |
348 KB |
Partially correct |
21 |
Partially correct |
1 ms |
604 KB |
Partially correct |
22 |
Partially correct |
0 ms |
604 KB |
Partially correct |
23 |
Partially correct |
1 ms |
348 KB |
Partially correct |
24 |
Partially correct |
0 ms |
348 KB |
Partially correct |
25 |
Partially correct |
1 ms |
348 KB |
Partially correct |
26 |
Partially correct |
1 ms |
348 KB |
Partially correct |
27 |
Partially correct |
1 ms |
348 KB |
Partially correct |
28 |
Partially correct |
0 ms |
348 KB |
Partially correct |
29 |
Partially correct |
1 ms |
600 KB |
Partially correct |
30 |
Partially correct |
0 ms |
604 KB |
Partially correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Partially correct |
1 ms |
348 KB |
Partially correct |
2 |
Partially correct |
0 ms |
348 KB |
Partially correct |
3 |
Partially correct |
0 ms |
348 KB |
Partially correct |
4 |
Partially correct |
1 ms |
348 KB |
Partially correct |
5 |
Partially correct |
0 ms |
348 KB |
Partially correct |
6 |
Partially correct |
0 ms |
348 KB |
Partially correct |
7 |
Partially correct |
0 ms |
348 KB |
Partially correct |
8 |
Partially correct |
0 ms |
348 KB |
Partially correct |
9 |
Partially correct |
0 ms |
348 KB |
Partially correct |
10 |
Partially correct |
0 ms |
348 KB |
Partially correct |
11 |
Partially correct |
0 ms |
348 KB |
Partially correct |
12 |
Partially correct |
0 ms |
344 KB |
Partially correct |
13 |
Partially correct |
0 ms |
348 KB |
Partially correct |
14 |
Partially correct |
0 ms |
348 KB |
Partially correct |
15 |
Partially correct |
1 ms |
344 KB |
Partially correct |
16 |
Partially correct |
0 ms |
348 KB |
Partially correct |
17 |
Partially correct |
0 ms |
348 KB |
Partially correct |
18 |
Partially correct |
1 ms |
344 KB |
Partially correct |
19 |
Partially correct |
1 ms |
344 KB |
Partially correct |
20 |
Partially correct |
0 ms |
348 KB |
Partially correct |
21 |
Partially correct |
1 ms |
348 KB |
Partially correct |
22 |
Partially correct |
1 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 |
348 KB |
Partially correct |
26 |
Partially correct |
1 ms |
460 KB |
Partially correct |
27 |
Partially correct |
1 ms |
604 KB |
Partially correct |
28 |
Partially correct |
1 ms |
604 KB |
Partially correct |
29 |
Partially correct |
0 ms |
604 KB |
Partially correct |
30 |
Partially correct |
1 ms |
604 KB |
Partially correct |
31 |
Partially correct |
1 ms |
600 KB |
Partially correct |
32 |
Partially correct |
1 ms |
348 KB |
Partially correct |
33 |
Partially correct |
0 ms |
348 KB |
Partially correct |
34 |
Partially correct |
1 ms |
604 KB |
Partially correct |
35 |
Partially correct |
1 ms |
348 KB |
Partially correct |
36 |
Partially correct |
1 ms |
604 KB |
Partially correct |
37 |
Partially correct |
1 ms |
348 KB |
Partially correct |
38 |
Partially correct |
1 ms |
604 KB |
Partially correct |
39 |
Partially correct |
0 ms |
604 KB |
Partially correct |
40 |
Partially correct |
1 ms |
348 KB |
Partially correct |
41 |
Partially correct |
0 ms |
348 KB |
Partially correct |
42 |
Partially correct |
1 ms |
348 KB |
Partially correct |
43 |
Partially correct |
1 ms |
348 KB |
Partially correct |
44 |
Partially correct |
1 ms |
348 KB |
Partially correct |
45 |
Partially correct |
0 ms |
348 KB |
Partially correct |
46 |
Partially correct |
1 ms |
600 KB |
Partially correct |
47 |
Partially correct |
0 ms |
604 KB |
Partially correct |
48 |
Partially correct |
44 ms |
12964 KB |
Partially correct |
49 |
Partially correct |
41 ms |
14164 KB |
Partially correct |
50 |
Partially correct |
54 ms |
14160 KB |
Partially correct |
51 |
Partially correct |
31 ms |
11096 KB |
Partially correct |
52 |
Partially correct |
41 ms |
13948 KB |
Partially correct |
53 |
Partially correct |
36 ms |
12416 KB |
Partially correct |
54 |
Partially correct |
24 ms |
10588 KB |
Partially correct |
55 |
Partially correct |
59 ms |
21076 KB |
Partially correct |
56 |
Partially correct |
46 ms |
17232 KB |
Partially correct |
57 |
Partially correct |
47 ms |
15956 KB |
Partially correct |
58 |
Partially correct |
51 ms |
15132 KB |
Partially correct |
59 |
Partially correct |
46 ms |
14160 KB |
Partially correct |
60 |
Partially correct |
36 ms |
14804 KB |
Partially correct |
61 |
Partially correct |
41 ms |
15152 KB |
Partially correct |
62 |
Partially correct |
41 ms |
14936 KB |
Partially correct |
63 |
Partially correct |
39 ms |
13908 KB |
Partially correct |
64 |
Partially correct |
39 ms |
14672 KB |
Partially correct |
65 |
Partially correct |
50 ms |
14928 KB |
Partially correct |
66 |
Partially correct |
34 ms |
14172 KB |
Partially correct |
67 |
Partially correct |
28 ms |
11088 KB |
Partially correct |
68 |
Partially correct |
33 ms |
12624 KB |
Partially correct |
69 |
Partially correct |
37 ms |
14940 KB |
Partially correct |
70 |
Partially correct |
34 ms |
14172 KB |
Partially correct |
71 |
Partially correct |
26 ms |
10588 KB |
Partially correct |
72 |
Partially correct |
29 ms |
11864 KB |
Partially correct |
73 |
Partially correct |
39 ms |
14928 KB |
Partially correct |
74 |
Partially correct |
46 ms |
13648 KB |
Partially correct |
75 |
Partially correct |
40 ms |
13912 KB |
Partially correct |
76 |
Partially correct |
42 ms |
13904 KB |
Partially correct |
77 |
Partially correct |
40 ms |
13908 KB |
Partially correct |
78 |
Partially correct |
27 ms |
9820 KB |
Partially correct |
79 |
Partially correct |
31 ms |
11352 KB |
Partially correct |
80 |
Partially correct |
43 ms |
13904 KB |
Partially correct |
81 |
Partially correct |
43 ms |
14168 KB |
Partially correct |
82 |
Partially correct |
38 ms |
14680 KB |
Partially correct |