Submission #851050

#TimeUsernameProblemLanguageResultExecution timeMemory
851050emkowNetwork (BOI15_net)C++17
0 / 100
1 ms600 KiB
#include <bits/stdc++.h> #pragma GCC optimize("O3", "unroll-loops") #define pb emplace_back #define ins insert #define ssize(x) (int)x.size() #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() #define pii pair <int, int> #define pll pair <ll, ll> #define pld pair <ld, ld> #define st first #define nd second using namespace std; using ll = int_fast64_t; // using lll = __int128_t; using ld = long double; const int oo = 1e9 + 7; const int mod = 1e9 + 7; void solve(){ int n; cin >> n; vector <int> deg(n, 0); for(int i = 1; i < n; i ++){ int a, b; cin >> a >> b; -- a; -- b; deg[a] ++; deg[b] ++; } vector <int> leaves; for(int i = 0; i < n; i ++){ if(deg[i] == 1) leaves.pb(i); } cout << (ssize(leaves) + 1) / 2 << '\n'; for(int i = 0; i < ssize(leaves) / 2; i ++){ cout << leaves[i] + 1 << ' ' << leaves[i + ssize(leaves) / 2] + 1 << '\n'; } if(ssize(leaves) & 1) cout << leaves[0] + 1 << ' ' << leaves.back() + 1 << '\n'; } signed main(){ ios_base::sync_with_stdio(0); cin.tie(0); int t; t = 1; // cin >> t; while(t --) solve(); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...