제출 #394455

#제출 시각아이디문제언어결과실행 시간메모리
394455AlmaNetwork (BOI15_net)C++14
100 / 100
487 ms51944 KiB
#include <bits/stdc++.h> using namespace std; vector<int> a; void f (int p, int n, vector<vector<int>> & g) { if ((int)g[n].size() == 1) a.push_back(n); for (int c: g[n]) { if (c != p) f (n, c, g); } } int main() { ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n, u, v, s; cin >> n; vector<vector<int>> g(n, vector<int>()); for (int i = 0; i < n-1; i++) { cin >> u >> v; u--; v--; g[u].push_back(v); g[v].push_back(u); } f (-1, 0, g); cout << ((int)a.size() + 1) / 2 << '\n'; s = (int)a.size() / 2; for (int i = 0; i < s; i++) { cout << a[i] + 1 << ' ' << a[s+i] + 1 << '\n'; } s = (int)a.size(); if (s % 2 == 1) cout << a[0] + 1 << ' ' << a[s-1] + 1 << '\n'; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...