제출 #1174023

#제출 시각아이디문제언어결과실행 시간메모리
1174023iamhereforfunNetwork (BOI15_net)C++20
100 / 100
337 ms45304 KiB
// IamHereForFun // #include <bits/stdc++.h> using namespace std; #define LSOne(S) ((S) & -(S)) const int N = 5e5 + 5; const int Q = 2e5 + 5; const int M = 1e6 + 5; const int LG = 18; const int P = 31; const long long INF = 4e18; const int MOD = 1e9; int n, sz = 0; vector<vector<int>> adj(N); vector<int> leaves; void setLeaves(int cur, int par) { if (adj[cur].size() == 1) { leaves.push_back(cur); } for (int i : adj[cur]) { if (i == par) continue; setLeaves(i, cur); } } void prtSolve() { cin >> n; for (int x = 0; x < n - 1; x++) { int a, b; cin >> a >> b; adj[a].push_back(b); adj[b].push_back(a); } setLeaves(1, 0); sz = leaves.size(); cout << (sz + 1) / 2 << "\n"; for (int x = 0; x < sz / 2; x++) { cout << leaves[x] << " " << leaves[x + (sz + 1) / 2] << "\n"; } if (sz % 2 == 1) { cout << 1 << " " << leaves[sz / 2] << "\n"; } } signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int t = 1; // cin >> t; for (int x = 1; x <= t; x++) { prtSolve(); } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...