Submission #1092852

#TimeUsernameProblemLanguageResultExecution timeMemory
1092852juicyNetwork (BOI15_net)C++17
100 / 100
301 ms61524 KiB
#include <bits/stdc++.h> using namespace std; #ifdef LOCAL #include "debug.h" #else #define debug(...) 42 #endif int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n; cin >> n; vector<vector<int>> g(n); for (int i = 1; i < n; ++i) { int u, v; cin >> u >> v; --u, --v; g[u].push_back(v); g[v].push_back(u); } vector<int> cnd; function<void(int, int)> dfs = [&](int u, int p) { if (g[u].size() == 1) { cnd.push_back(u + 1); } for (auto v : g[u]) { if (v ^ p) { dfs(v, u); } } }; dfs(1, 1); if (cnd.size() & 1) { cnd.push_back(cnd[0]); } int m = cnd.size() / 2; cout << m << "\n"; for (int i = 0; i < m; ++i) { cout << cnd[i] << " " << cnd[i + m] << "\n"; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...