# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1102080 |
2024-10-17T11:45:28 Z |
razivo |
Village (BOI20_village) |
C++14 |
|
81 ms |
22136 KB |
#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]+1<<" ";
}
cout<<endl;
for (int i = 0; i < n; ++i) {
cout<<perm[i]+1<<" ";
}
cout<<endl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Partially correct |
1 ms |
336 KB |
Partially correct |
2 |
Partially correct |
1 ms |
336 KB |
Partially correct |
3 |
Partially correct |
0 ms |
336 KB |
Partially correct |
4 |
Partially correct |
1 ms |
336 KB |
Partially correct |
5 |
Partially correct |
1 ms |
336 KB |
Partially correct |
6 |
Partially correct |
0 ms |
336 KB |
Partially correct |
7 |
Partially correct |
1 ms |
336 KB |
Partially correct |
8 |
Partially correct |
1 ms |
336 KB |
Partially correct |
9 |
Partially correct |
1 ms |
336 KB |
Partially correct |
10 |
Partially correct |
1 ms |
336 KB |
Partially correct |
11 |
Partially correct |
1 ms |
336 KB |
Partially correct |
12 |
Partially correct |
0 ms |
336 KB |
Partially correct |
13 |
Partially correct |
1 ms |
336 KB |
Partially correct |
14 |
Partially correct |
1 ms |
336 KB |
Partially correct |
15 |
Partially correct |
1 ms |
336 KB |
Partially correct |
16 |
Partially correct |
1 ms |
336 KB |
Partially correct |
17 |
Partially correct |
1 ms |
336 KB |
Partially correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Partially correct |
1 ms |
504 KB |
Partially correct |
2 |
Partially correct |
1 ms |
336 KB |
Partially correct |
3 |
Partially correct |
1 ms |
336 KB |
Partially correct |
4 |
Partially correct |
1 ms |
336 KB |
Partially correct |
5 |
Partially correct |
1 ms |
336 KB |
Partially correct |
6 |
Partially correct |
1 ms |
336 KB |
Partially correct |
7 |
Partially correct |
1 ms |
592 KB |
Partially correct |
8 |
Partially correct |
1 ms |
336 KB |
Partially correct |
9 |
Partially correct |
1 ms |
336 KB |
Partially correct |
10 |
Partially correct |
1 ms |
336 KB |
Partially correct |
11 |
Partially correct |
1 ms |
592 KB |
Partially correct |
12 |
Partially correct |
1 ms |
336 KB |
Partially correct |
13 |
Partially correct |
1 ms |
336 KB |
Partially correct |
14 |
Partially correct |
1 ms |
336 KB |
Partially correct |
15 |
Partially correct |
1 ms |
336 KB |
Partially correct |
16 |
Partially correct |
1 ms |
336 KB |
Partially correct |
17 |
Partially correct |
1 ms |
336 KB |
Partially correct |
18 |
Partially correct |
1 ms |
504 KB |
Partially correct |
19 |
Partially correct |
1 ms |
336 KB |
Partially correct |
20 |
Partially correct |
1 ms |
504 KB |
Partially correct |
21 |
Partially correct |
1 ms |
336 KB |
Partially correct |
22 |
Partially correct |
1 ms |
336 KB |
Partially correct |
23 |
Partially correct |
2 ms |
336 KB |
Partially correct |
24 |
Partially correct |
1 ms |
336 KB |
Partially correct |
25 |
Partially correct |
1 ms |
508 KB |
Partially correct |
26 |
Partially correct |
1 ms |
336 KB |
Partially correct |
27 |
Partially correct |
1 ms |
336 KB |
Partially correct |
28 |
Partially correct |
1 ms |
336 KB |
Partially correct |
29 |
Partially correct |
1 ms |
336 KB |
Partially correct |
30 |
Partially correct |
2 ms |
336 KB |
Partially correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Partially correct |
1 ms |
336 KB |
Partially correct |
2 |
Partially correct |
1 ms |
336 KB |
Partially correct |
3 |
Partially correct |
0 ms |
336 KB |
Partially correct |
4 |
Partially correct |
1 ms |
336 KB |
Partially correct |
5 |
Partially correct |
1 ms |
336 KB |
Partially correct |
6 |
Partially correct |
0 ms |
336 KB |
Partially correct |
7 |
Partially correct |
1 ms |
336 KB |
Partially correct |
8 |
Partially correct |
1 ms |
336 KB |
Partially correct |
9 |
Partially correct |
1 ms |
336 KB |
Partially correct |
10 |
Partially correct |
1 ms |
336 KB |
Partially correct |
11 |
Partially correct |
1 ms |
336 KB |
Partially correct |
12 |
Partially correct |
0 ms |
336 KB |
Partially correct |
13 |
Partially correct |
1 ms |
336 KB |
Partially correct |
14 |
Partially correct |
1 ms |
336 KB |
Partially correct |
15 |
Partially correct |
1 ms |
336 KB |
Partially correct |
16 |
Partially correct |
1 ms |
336 KB |
Partially correct |
17 |
Partially correct |
1 ms |
336 KB |
Partially correct |
18 |
Partially correct |
1 ms |
504 KB |
Partially correct |
19 |
Partially correct |
1 ms |
336 KB |
Partially correct |
20 |
Partially correct |
1 ms |
336 KB |
Partially correct |
21 |
Partially correct |
1 ms |
336 KB |
Partially correct |
22 |
Partially correct |
1 ms |
336 KB |
Partially correct |
23 |
Partially correct |
1 ms |
336 KB |
Partially correct |
24 |
Partially correct |
1 ms |
592 KB |
Partially correct |
25 |
Partially correct |
1 ms |
336 KB |
Partially correct |
26 |
Partially correct |
1 ms |
336 KB |
Partially correct |
27 |
Partially correct |
1 ms |
336 KB |
Partially correct |
28 |
Partially correct |
1 ms |
592 KB |
Partially correct |
29 |
Partially correct |
1 ms |
336 KB |
Partially correct |
30 |
Partially correct |
1 ms |
336 KB |
Partially correct |
31 |
Partially correct |
1 ms |
336 KB |
Partially correct |
32 |
Partially correct |
1 ms |
336 KB |
Partially correct |
33 |
Partially correct |
1 ms |
336 KB |
Partially correct |
34 |
Partially correct |
1 ms |
336 KB |
Partially correct |
35 |
Partially correct |
1 ms |
504 KB |
Partially correct |
36 |
Partially correct |
1 ms |
336 KB |
Partially correct |
37 |
Partially correct |
1 ms |
504 KB |
Partially correct |
38 |
Partially correct |
1 ms |
336 KB |
Partially correct |
39 |
Partially correct |
1 ms |
336 KB |
Partially correct |
40 |
Partially correct |
2 ms |
336 KB |
Partially correct |
41 |
Partially correct |
1 ms |
336 KB |
Partially correct |
42 |
Partially correct |
1 ms |
508 KB |
Partially correct |
43 |
Partially correct |
1 ms |
336 KB |
Partially correct |
44 |
Partially correct |
1 ms |
336 KB |
Partially correct |
45 |
Partially correct |
1 ms |
336 KB |
Partially correct |
46 |
Partially correct |
1 ms |
336 KB |
Partially correct |
47 |
Partially correct |
2 ms |
336 KB |
Partially correct |
48 |
Partially correct |
58 ms |
10312 KB |
Partially correct |
49 |
Partially correct |
69 ms |
11432 KB |
Partially correct |
50 |
Partially correct |
66 ms |
11272 KB |
Partially correct |
51 |
Partially correct |
52 ms |
9028 KB |
Partially correct |
52 |
Partially correct |
66 ms |
11336 KB |
Partially correct |
53 |
Partially correct |
57 ms |
10060 KB |
Partially correct |
54 |
Partially correct |
39 ms |
11344 KB |
Partially correct |
55 |
Partially correct |
76 ms |
22136 KB |
Partially correct |
56 |
Partially correct |
73 ms |
16072 KB |
Partially correct |
57 |
Partially correct |
71 ms |
13896 KB |
Partially correct |
58 |
Partially correct |
68 ms |
12732 KB |
Partially correct |
59 |
Partially correct |
64 ms |
11356 KB |
Partially correct |
60 |
Partially correct |
54 ms |
10524 KB |
Partially correct |
61 |
Partially correct |
67 ms |
10792 KB |
Partially correct |
62 |
Partially correct |
56 ms |
10824 KB |
Partially correct |
63 |
Partially correct |
55 ms |
10056 KB |
Partially correct |
64 |
Partially correct |
79 ms |
10944 KB |
Partially correct |
65 |
Partially correct |
63 ms |
11084 KB |
Partially correct |
66 |
Partially correct |
50 ms |
10056 KB |
Partially correct |
67 |
Partially correct |
42 ms |
8008 KB |
Partially correct |
68 |
Partially correct |
49 ms |
9260 KB |
Partially correct |
69 |
Partially correct |
54 ms |
10872 KB |
Partially correct |
70 |
Partially correct |
52 ms |
10312 KB |
Partially correct |
71 |
Partially correct |
39 ms |
7496 KB |
Partially correct |
72 |
Partially correct |
46 ms |
8520 KB |
Partially correct |
73 |
Partially correct |
57 ms |
10824 KB |
Partially correct |
74 |
Partially correct |
48 ms |
10068 KB |
Partially correct |
75 |
Partially correct |
61 ms |
11336 KB |
Partially correct |
76 |
Partially correct |
79 ms |
10824 KB |
Partially correct |
77 |
Partially correct |
54 ms |
10604 KB |
Partially correct |
78 |
Partially correct |
42 ms |
7240 KB |
Partially correct |
79 |
Partially correct |
56 ms |
8264 KB |
Partially correct |
80 |
Partially correct |
81 ms |
11292 KB |
Partially correct |
81 |
Partially correct |
61 ms |
10724 KB |
Partially correct |
82 |
Partially correct |
59 ms |
10568 KB |
Partially correct |