제출 #380563

#제출 시각아이디문제언어결과실행 시간메모리
380563vishesh312Network (BOI15_net)C++17
0 / 100
1 ms364 KiB
#include "bits/stdc++.h" using namespace std; /* #include <ext/pb_ds/assoc_container.hpp> using namespace __gnu_pbds; using ordered_set = tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>; */ #define all(x) begin(x), end(x) #define sz(x) (int)x.size() using ll = long long; const int mod = 1e9+7; void solve(int tc) { int n; cin >> n; vector<vector<int>> adj(n); for (int i = 0; i < n-1; ++i) { int u, v; cin >> u >> v; --u, --v; adj[u].push_back(v); adj[v].push_back(u); } vector<int> leaf; for (int i = 0; i < n; ++i) { if (sz(adj[i]) == 1) { leaf.push_back(i); } } cout << (sz(leaf)+1)/2 << '\n'; for (int i = 0; i < sz(leaf)/2; ++i) { cout << leaf[i]+1 << " " << leaf[i+sz(leaf)/2]+1 << '\n'; } if (sz(leaf)&1) cout << leaf[0]+1 << " " << leaf.back()+1 << '\n'; } signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int tc = 1; //cin >> tc; for (int i = 1; i <= tc; ++i) solve(i); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...