Submission #1036995

#TimeUsernameProblemLanguageResultExecution timeMemory
1036995___Network (BOI15_net)C++17
0 / 100
0 ms348 KiB
#include <bits/stdc++.h> #define int long long int #define ff first #define ss second #define FT ios_base::sync_with_stdio(false);cin.tie(0); using namespace std; const int maxn = 5e5 + 10; int degree[maxn]; vector <int> leaf; signed main() { FT; int n; cin >> n; for (int i = 1 ; i < n ; i++) { int a , b; cin >> a >> b; degree[a]++; degree[b]++; } for (int i = 1 ; i <= n ; i++) { if (degree[i] == 1) { leaf.push_back(i); } } int k = leaf.size(); cout << (k + 1) / 2 << endl; for (int i = 0 ; i < k - 1 ; i += 2) { cout << leaf[i] << " " << leaf[i + 1] << endl; } if (k % 2) { cout << leaf[k - 2] << " " << leaf[k - 1]; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...