제출 #556742

#제출 시각아이디문제언어결과실행 시간메모리
556742HanksburgerNetwork (BOI15_net)C++17
100 / 100
430 ms47724 KiB
#include <bits/stdc++.h> using namespace std; vector<int> adj[500005], vec; void dfs(int u, int p) { if (adj[u].size()==1) vec.push_back(u); for (int v:adj[u]) if (v!=p) dfs(v, u); } int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, sz; cin >> n; for (int i=1; i<n; i++) { int u, v; cin >> u >> v; adj[u].push_back(v); adj[v].push_back(u); } dfs(1, 0); sz=vec.size(); cout << (sz+1)/2 << '\n'; for (int i=0; i<(sz+1)/2; i++) cout << vec[i] << ' ' << vec[i+sz/2] << '\n'; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...