제출 #749847

#제출 시각아이디문제언어결과실행 시간메모리
749847JellyTheOctopusNetwork (BOI15_net)C++17
0 / 100
7 ms11988 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 = 1; 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...