제출 #394603

#제출 시각아이디문제언어결과실행 시간메모리
394603AmShZNetwork (BOI15_net)C++11
100 / 100
641 ms51392 KiB
// khodaya khodet komak kon // Toxicity # include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; typedef pair <int, int> pii; typedef pair <pii, int> ppi; typedef pair <int, pii> pip; typedef pair <pii, pii> ppp; typedef pair <ll, ll> pll; # define A first # define B second # define endl '\n' # define sep ' ' # define all(x) x.begin(), x.end() # define kill(x) return cout << x << endl, 0 # define SZ(x) int(x.size()) # define lc id << 1 # define rc id << 1 | 1 # define InTheNameOfGod ios::sync_with_stdio(0);cin.tie(0); cout.tie(0); ll power(ll a, ll b, ll md) {return (!b ? 1 : (b & 1 ? a * power(a * a % md, b / 2, md) % md : power(a * a % md, b / 2, md) % md));} const int xn = 5e5 + 10; const int xm = - 20 + 10; const int sq = 320; const int inf = 1e9 + 10; const ll INF = 1e18 + 10; const int mod = 998244353; const int base = 257; int n, sz[xn], root, m, a[xn]; vector <int> adj[xn]; void plant(int v, int p = - 1){ sz[v] = 1; for (int u : adj[v]) if (u != p) plant(u, v), sz[v] += sz[u]; } int find_centroid(int v, int p = - 1){ for (int u : adj[v]) if (u != p && sz[u] + sz[u] > n) return find_centroid(u, v); return v; } void DFS(int v, int p = - 1){ if (SZ(adj[v]) == 1) a[m ++] = v; for (int u : adj[v]) if (u != p) DFS(u, v); } int main(){ InTheNameOfGod; cin >> n; for (int i = 0; i < n - 1; ++ i){ int v, u; cin >> v >> u; adj[v].push_back(u); adj[u].push_back(v); } plant(1); root = find_centroid(1); DFS(root); cout << (m + 1) / 2 << endl; for (int i = 0; i < (m + 1) / 2; ++ i) cout << a[i] << sep << a[i + m / 2] << endl; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...