# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
723533 | 2023-04-14T04:04:37 Z | t6twotwo | Village (BOI20_village) | C++17 | 1 ms | 320 KB |
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n; cin >> n; vector<vector<int>> adj(n); for (int i = 1; i < n; i++) { int x; cin >> x; x--; int y; cin >> y; y--; adj[x].push_back(y); adj[y].push_back(x); } vector<int> a(n); iota(a.begin(), a.end(), 0); int ans = 0; auto dfs = [&](auto dfs, int x, int p) -> bool { vector<int> b; for (int y : adj[x]) { if (y != p) { if (dfs(dfs, y, x)) { b.push_back(y); } } } if (b.empty()) { return 1; } ans += b.size() * 2; if (b.size() % 2 == 1) { swap(a[x], a[b[0]]); for (int i = 1; i < b.size(); i++) { swap(a[b[i]], a[b[i + 1]]); } } else { swap(a[x], a[b[0]]); swap(a[x], a[b[1]]); for (int i = 2; i < b.size(); i++) { swap(a[b[i]], a[b[i + 1]]); } } return 0; }; if (dfs(dfs, 0, -1)) { swap(a[0], a[adj[0][0]]); ans += 2; } cout << ans << " " << 0 << "\n"; for (int i = 0; i < n; i++) { cout << a[i] + 1 << " \n"[i == n - 1]; } for (int i = 0; i < n; i++) { cout << 1 << " \n"[i == n - 1]; } return 6/22; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Partially correct | 1 ms | 212 KB | Partially correct |
2 | Partially correct | 1 ms | 212 KB | Partially correct |
3 | Partially correct | 1 ms | 316 KB | Partially correct |
4 | Partially correct | 1 ms | 212 KB | Partially correct |
5 | Partially correct | 1 ms | 212 KB | Partially correct |
6 | Partially correct | 1 ms | 212 KB | Partially correct |
7 | Partially correct | 0 ms | 320 KB | Partially correct |
8 | Partially correct | 1 ms | 212 KB | Partially correct |
9 | Incorrect | 1 ms | 224 KB | Output isn't correct |
10 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 1 ms | 212 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Partially correct | 1 ms | 212 KB | Partially correct |
2 | Partially correct | 1 ms | 212 KB | Partially correct |
3 | Partially correct | 1 ms | 316 KB | Partially correct |
4 | Partially correct | 1 ms | 212 KB | Partially correct |
5 | Partially correct | 1 ms | 212 KB | Partially correct |
6 | Partially correct | 1 ms | 212 KB | Partially correct |
7 | Partially correct | 0 ms | 320 KB | Partially correct |
8 | Partially correct | 1 ms | 212 KB | Partially correct |
9 | Incorrect | 1 ms | 224 KB | Output isn't correct |
10 | Halted | 0 ms | 0 KB | - |