제출 #26108

#제출 시각아이디문제언어결과실행 시간메모리
26108bugmenot111Network (BOI15_net)C++14
100 / 100
726 ms43112 KiB
#include <cstdio> #include <vector> #define MAXN 500500 std::vector<int> g[MAXN]; int leaves[MAXN], leaves_top; void dfs(int v, int p) { if(g[v].size() == 1) leaves[leaves_top++] = v; for(int c: g[v]) if(c != p) dfs(c, v); } int main(void) { int n; scanf("%d", &n); for(int i = 1; i < n; i++) { int src, dst; scanf("%d%d", &src, &dst); src--; dst--; g[src].push_back(dst); g[dst].push_back(src); } dfs(0, -1); int nv = (leaves_top + 1) / 2; printf("%d\n", nv); for(int i = 0; i < nv; i++) { int src = leaves[i]; int dst = leaves[(i + nv) % leaves_top]; src++; dst++; printf("%d %d\n", src, dst); } return 0; }

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

net.cpp: In function 'int main()':
net.cpp:12:17: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &n);
                 ^
net.cpp:15:28: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d", &src, &dst);
                            ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...