제출 #1037003

#제출 시각아이디문제언어결과실행 시간메모리
1037003___Network (BOI15_net)C++17
100 / 100
498 ms48588 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; vector <int> adj[maxn]; vector <int> leaf; void dfs (int v , int g) { if (adj[v].size() == 1) { leaf.push_back(v); } for (auto u : adj[v]) { if (u != g) { dfs (u , v); } } } signed main() { FT; int n; cin >> n; for (int i = 1 ; i < n ; i++) { int a , b; cin >> a >> b; adj[a].push_back(b); adj[b].push_back(a); } for (int i = 1 ; i <= n ; i++) { if (adj[i].size() > 1) { dfs (i , 0); break; } } int k = leaf.size(); cout << (k + 1) / 2 << endl; for (int i = 0 ; i < (k + 1) / 2 ; i++) { cout << leaf[i] << " " << leaf[i + k / 2] << endl; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...