제출 #679583

#제출 시각아이디문제언어결과실행 시간메모리
679583peijarNetwork (BOI15_net)C++17
100 / 100
419 ms46660 KiB
#include <bits/stdc++.h> #define int long long using namespace std; namespace std { template <typename T> ostream &operator<<(ostream &out, const vector<T> &vec) { out << "["; for (int i = 0; i < (int)vec.size(); ++i) { out << vec[i]; if (i + 1 < (int)vec.size()) out << ", "; } return out << "]"; } } // namespace std void dbg_out() { cout << endl; } template <typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cout << ' ' << H; dbg_out(T...); } #ifdef DEBUG #define dbg(...) cout << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__) #else #define dbg(...) #endif signed main(void) { ios_base::sync_with_stdio(false); cin.tie(0); int nbSommet; cin >> nbSommet; vector<vector<int>> adj(nbSommet); for (int i = 1; i < nbSommet; ++i) { int u, v; cin >> u >> v; --u, --v; adj[u].push_back(v); adj[v].push_back(u); } vector<int> feuilles; auto DFS = [&](auto dfs, int u, int p) -> void { if (adj[u].size() == 1) feuilles.push_back(u); for (int v : adj[u]) if (v != p) dfs(dfs, v, u); }; for (int u = 0; u < nbSommet; ++u) if (adj[u].size() > 1) { DFS(DFS, u, u); break; } int nbFeuilles = feuilles.size(); int delta = (nbFeuilles + 1) / 2; cout << (nbFeuilles + 1) / 2 << endl; for (int i = 0; i < (nbFeuilles + 1) / 2; ++i) cout << 1 + feuilles[i] << ' ' << feuilles[(i + delta) % nbFeuilles] + 1 << '\n'; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...