제출 #790126

#제출 시각아이디문제언어결과실행 시간메모리
790126tch1cherinNetwork (BOI15_net)C++17
100 / 100
610 ms51968 KiB
#include <bits/stdc++.h> using namespace std; const int MAX_N = 500005; vector<int> G[MAX_N]; vector<int> ord; void DFS(int u, int p) { for (int v : G[u]) { if (v != p) { DFS(v, u); } } if (G[u].size() == 1) { ord.push_back(u); } } int main() { int N; cin >> N; for (int i = 0; i < N - 1; i++) { int u, v; cin >> u >> v; u--, v--; G[u].push_back(v); G[v].push_back(u); } DFS(0, -1); int L = (int)ord.size(); cout << (L + 1) / 2 << "\n"; for (int i = 0; i < (L + 1) / 2; i++) { cout << 1 + ord[i] << " " << 1 + ord[i + L / 2] << "\n"; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...