Submission #529316

#TimeUsernameProblemLanguageResultExecution timeMemory
529316Alex_tz307Network (BOI15_net)C++17
0 / 100
1 ms316 KiB
#include <bits/stdc++.h> using namespace std; void testCase() { int n; cin >> n; vector<int> d(n + 1); for (int i = 1; i < n; ++i) { int u, v; cin >> u >> v; d[u] += 1; d[v] += 1; } int node = -1; vector<int> v; for (int i = 1; i <= n; ++i) { if (d[i] == 1) { v.emplace_back(i); } else { node = i; } } if ((int)v.size() % 2 == 1) { v.emplace_back(node); } cout << v.size() / 2 << '\n'; for (int i = 0; i < (int)v.size(); i += 2) { cout << v[i] << ' ' << v[i + 1] << '\n'; } } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); int tests = 1; for (int tc = 0; tc < tests; ++tc) { testCase(); } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...