제출 #1033239

#제출 시각아이디문제언어결과실행 시간메모리
1033239aufanNetwork (BOI15_net)C++17
0 / 100
1 ms348 KiB
#include <bits/stdc++.h> #define int long long #define fi first #define se second using namespace std; int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n; cin >> n; vector<int> deg(n + 1); for (int i = 0; i < n - 1; i++) { int a, b; cin >> a >> b; deg[a] += 1; deg[b] += 1; } vector<int> leafs; // lol for (int i = 1; i <= n; i++) { if (deg[i] == 1) { leafs.push_back(i); } } if ((int)leafs.size() % 2 == 1) { for (int i = 1; i <= n; i++) { if (deg[i] > 1) { leafs.push_back(i); break; } } } vector<pair<int, int>> ans; for (int i = 0; i < (int)leafs.size(); i += 2) { ans.push_back({leafs[i], leafs[i + 1]}); } cout << (int)ans.size() << '\n'; for (auto [a, b] : ans) cout << a << " " << b << '\n'; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...