Submission #723534

#TimeUsernameProblemLanguageResultExecution timeMemory
723534t6twotwoVillage (BOI20_village)C++17
50 / 100
102 ms23156 KiB
#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 += 2) { 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 += 2) { 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 (stderr)

Village.cpp: In lambda function:
Village.cpp:33:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   33 |             for (int i = 1; i < b.size(); i += 2) {
      |                             ~~^~~~~~~~~~
Village.cpp:39:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   39 |             for (int i = 2; i < b.size(); i += 2) {
      |                             ~~^~~~~~~~~~
Village.cpp: In instantiation of 'main()::<lambda(auto:23, int, int)> [with auto:23 = main()::<lambda(auto:23, int, int)>]':
Village.cpp:45:23:   required from here
Village.cpp:33:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   33 |             for (int i = 1; i < b.size(); i += 2) {
      |                             ~~^~~~~~~~~~
Village.cpp:39:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   39 |             for (int i = 2; i < b.size(); i += 2) {
      |                             ~~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...