Submission #550586

#TimeUsernameProblemLanguageResultExecution timeMemory
550586OttoTheDinoNetwork (BOI15_net)C++17
100 / 100
428 ms47704 KiB
#include <bits/stdc++.h> using namespace std; #define rep(i,s,e) for (int i = s; i <= e; ++i) #define rrep(i,s,e) for (int i = s; i >= e; --i) #define pb push_back #define pf push_front #define fi first #define se second #define all(a) a.begin(), a.end() #define SZ(a) (int)a.size() typedef long long ll; typedef pair<int, int> ii; typedef vector<ii> vii; typedef vector<int> vi; typedef vector<double> vd; typedef vector<string> vs; typedef vector<ll> vll; const int mx = 5e5; vi adj[mx+1], leaves; int x; void dfs (int u, int p) { if (SZ(adj[u])==1) leaves.pb(u); else x = u; for (int v : adj[u]) { if (v==p) continue; dfs (v,u); } } int main() { ios::sync_with_stdio(0); cin.tie(0); int n; cin >> n; rep (i,1,n-1) { int u, v; cin >> u >> v; adj[u].pb(v); adj[v].pb(u); } dfs (1,-1); int m = leaves.size(); cout << (m+1)/2 << "\n"; rep (i,0,m/2-1) { cout << leaves[i] << " " << leaves[i+m/2] << "\n"; } if (m%2) cout << leaves[m-1] << " " << leaves[m/2] << "\n"; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...