Submission #622014

#TimeUsernameProblemLanguageResultExecution timeMemory
622014MinaRagy06Network (BOI15_net)C++17
0 / 100
1 ms340 KiB
#include <bits/stdc++.h> using namespace std; #define lesgooo ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0) #define endl '\n' #define int long long signed main() { lesgooo; int n, u, v; cin >> n; vector<int> adj[n]; for (int i = 1; i < n; i++) cin >> u >> v, adj[--u].push_back(--v), adj[v].push_back(u); set<int> leaf; for (int i = 0;i < n; i++) if (adj[i].size() == 1) leaf.insert(i); cout << (leaf.size()+1)/2 << endl; int temp = *leaf.begin(); while (leaf.size()) { cout << *leaf.begin()+1 << " ", leaf.erase(leaf.begin()); if (leaf.size()) cout << *leaf.begin()+1 << endl, leaf.erase(leaf.begin()); else cout << temp+1 << endl; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...