제출 #30484

#제출 시각아이디문제언어결과실행 시간메모리
30484sampritiNetwork (BOI15_net)C++14
100 / 100
783 ms41660 KiB
#include <cstdio> #include <algorithm> #include <vector> #include <cassert> using namespace std; vector<int> G[500001]; vector<int> leaves; void dfs(int i, int p) { if(G[i].size() == 1) leaves.push_back(i); for(int j = 0; j < G[i].size(); j++) { int u = G[i][j]; if(u == p) continue; dfs(u, i); } } int main() { int N; scanf("%d", &N); for(int i = 0; i < N - 1; i++) { int a, b; scanf("%d %d", &a, &b); G[a].push_back(b); G[b].push_back(a); } dfs(1, 0); int ans = (leaves.size() + 1)/2; printf("%d\n", ans); for(int i = 0; i < ans; i++) { assert((i + leaves.size()/2) < leaves.size()); printf("%d %d\n", leaves[i], leaves[i + leaves.size()/2]); } }

컴파일 시 표준 에러 (stderr) 메시지

net.cpp: In function 'void dfs(int, int)':
net.cpp:14:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int j = 0; j < G[i].size(); j++) {
                    ^
net.cpp: In function 'int main()':
net.cpp:22:25: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   int N; scanf("%d", &N);
                         ^
net.cpp:25:37: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     int a, b; scanf("%d %d", &a, &b);
                                     ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...