Submission #79580

#TimeUsernameProblemLanguageResultExecution timeMemory
79580VinhspmNetwork (BOI15_net)C++14
100 / 100
699 ms45592 KiB
#include<bits/stdc++.h> using namespace std; #define fi first #define se second #define pb push_back typedef pair<int, int> ii; const int N = 5e5 + 10; const int oo = 1e9; int n, cnt; int leaf[N]; bool visit[N]; vector<int> lef, rig, vi[N]; void dfs(int pre, int u) { for(int v: vi[u]) if(v != pre) dfs(u, v); if(vi[u].size() == 1) leaf[++cnt] = u; } signed main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n; for(int i = 1; i < n; ++i) { int u, v; cin >> u >> v; vi[u].pb(v); vi[v].pb(u); } dfs(1, 1); cout << (cnt + 1) / 2 << '\n' ; for(int i = 1; i <= cnt / 2; ++i) cout << leaf[i] << ' ' << leaf[i + cnt / 2] << '\n' ; if(cnt % 2 == 1) cout << leaf[cnt] << ' ' << leaf[cnt - 1] << '\n'; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...