Submission #749846

#TimeUsernameProblemLanguageResultExecution timeMemory
749846JellyTheOctopusNetwork (BOI15_net)C++17
0 / 100
8 ms12048 KiB
#include <bits/stdc++.h> using namespace std; int N; vector<int> adjList[500001]; vector<int> leafNodes; void DFS(int node, int parent) { int numVertices = 0; for (auto child: adjList[node]) { numVertices++; if (child != parent) { DFS(child, node); } } if (numVertices == 1) { leafNodes.push_back(node); } } int main() { cin >> N; for (int i = 0; i < N-1; i++) { int u, v; cin >> u >> v; adjList[u].push_back(v); adjList[v].push_back(u); } DFS(1, -1); int M = (int)leafNodes.size(); cout << (M/2)+(M%2) << "\n"; for (int i = 0; i < M; i += 2) { cout << leafNodes[i] << " " << leafNodes[(i+1)%M] << "\n"; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...