제출 #1036989

#제출 시각아이디문제언어결과실행 시간메모리
1036989___Network (BOI15_net)C++17
0 / 100
0 ms416 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[0] << " " << leaf[k - 1]; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...