Submission #252223

#TimeUsernameProblemLanguageResultExecution timeMemory
252223BlagojceNetwork (BOI15_net)C++11
0 / 100
8 ms12160 KiB
#include <bits/stdc++.h> #define fr(i, n, m) for(int i = (n); i < (m); i ++) #define pb push_back #define st first #define nd second #define pq priority_queue #define all(x) begin(x), end(x) #include <time.h> #include <cmath> using namespace std; typedef long long ll; typedef long double ld; typedef pair<int,int> pii; const int i_inf = 1e9; const ll inf = 1e18; const ll mod = 1000000007; const ld eps = 1e-13; const ld pi = 3.14159265359; mt19937 _rand(time(NULL)); clock_t timer = clock(); const int mxn = 5e5; int n; vector<int> g[mxn]; vector<int> v; void dfs(int u, int p){ for(auto e : g[u]){ if(e == p) continue; dfs(e, u); } if((int)g[u].size() == 1){ v.pb(u); } } void solve(){ cin >> n; fr(i, 0, n-1){ int u, v; cin >> u >> v; --u, --v; g[u].pb(v); g[v].pb(u); } dfs(0, 0); vector<pii> ans; for(int i = 1; i < (int)v.size()-1; i += 2){ ans.pb({v[i], v[i+1]}); } ans.pb({v[0], v.back()}); cout<<ans.size()<<endl; for(auto u : ans) cout<<u.st+1<<' '<<u.nd+1<<endl; } int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); solve(); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...