Submission #442794

#TimeUsernameProblemLanguageResultExecution timeMemory
442794paliloNetwork (BOI15_net)C++17
0 / 100
1 ms308 KiB
#include <bits/stdc++.h> using namespace std; int main() { cin.tie(nullptr)->sync_with_stdio(false); #ifdef palilo freopen("in", "r", stdin); freopen("out", "w", stdout); #endif int n; cin >> n; vector<int> deg(n); for (int u, v, i = n - 1; i--;) { cin >> u >> v, --u, --v; ++deg[u], ++deg[v]; } vector<int> ans; for (int i = 0; i < n; ++i) { if (deg[i] == 1) { ans.emplace_back(i); } } const int leaves = count(deg.begin(), deg.end(), 1); cout << (leaves + 1) / 2 << '\n'; int prv = leaves & 1 ? int(find_if(deg.begin(), deg.end(), [&](const auto& x) { return x != 1; }) - deg.begin()) : -1; for (int i = 0; i < n; ++i) { if (deg[i] == 1) { if (prv == -1) { prv = i; } else { cout << prv + 1 << ' ' << i + 1 << '\n'; prv = -1; } } } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...