제출 #410597

#제출 시각아이디문제언어결과실행 시간메모리
410597iulia13Network (BOI15_net)C++14
100 / 100
1012 ms47640 KiB
#include <iostream> #include <vector> using namespace std; const int N = 500005; vector <int> g[N]; int nr = 0; vector <int> v; void dfs(int nod, int dad = 0) { if (g[nod].size() == 1) v.push_back(nod); for (auto x : g[nod]) if (x != dad) dfs(x, nod); } int main() { int n, i, a, b; cin >> n; for (i = 1; i < n; i++) { cin >> a >> b; g[a].push_back(b); g[b].push_back(a); } dfs(1); nr = v.size(); int ans = (nr + 1) / 2; cout << ans; for (i = 0; i < nr / 2; i ++) cout << endl << v[i] << " " << v[i + ans]; if (nr % 2) cout << endl << v[nr / 2] << " " << v[0]; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...