Submission #79535

#TimeUsernameProblemLanguageResultExecution timeMemory
79535VinhspmNetwork (BOI15_net)C++14
0 / 100
2 ms588 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; int deg[N]; 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; deg[u] ++; deg[v] ++; } vector<ii> ans; int las = -1; for(int i = 1; i <= n; ++i) if(deg[i] == 1) { if(las == -1) las = i; else ans.pb({i, las}), las = -1; } if(las != -1) for(int i = 1; i <= n; ++i) if(deg[i] == 1) { ans.pb(ii(las, i)); break; } cout << ans.size() << '\n'; for(ii v: ans) cout << v.fi << ' ' << v.se << '\n'; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...