제출 #25877

#제출 시각아이디문제언어결과실행 시간메모리
25877nibnalinNetwork (BOI15_net)C++14
100 / 100
723 ms42512 KiB
#include <iostream> #include <cstdio> #include <vector> #include <cmath> using namespace std; const int maxn = int(5e5)+5; vector<int> graph[maxn], S; void dfs(int node, int par) { if(int(graph[node].size()) == 1) S.push_back(node); for(auto it: graph[node]) { if(it != par) dfs(it, node); } } int main(void) { int n, u, v; scanf("%d", &n); for(int i = 1;i < n;i++) { scanf("%d%d", &u, &v); u--, v--; graph[u].push_back(v), graph[v].push_back(u); } dfs(0, -1); int res = ceil(int(S.size())/2.0); printf("%d\n", res); for(int i = 0;i < res;i++) { printf("%d %d\n", S[i]+1, S[(res+i)%int(S.size())]+1); } }

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

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