제출 #305452

#제출 시각아이디문제언어결과실행 시간메모리
305452shahriarkhanNetwork (BOI15_net)C++14
100 / 100
681 ms45940 KiB
#include<bits/stdc++.h> using namespace std ; const int siz = 5e5 + 69 ; vector<int> adj[siz] , ar ; int deg[siz] ; void dfs(int s , int p) { if(deg[s]==1) ar.push_back(s) ; for(int t : adj[s]) { if(t==p) continue ; dfs(t,s) ; } } int main() { int n ; scanf("%d",&n) ; for(int i = 1 ; i < n ; ++i) { int u , v ; scanf("%d%d",&u,&v) ; adj[u].push_back(v) ; adj[v].push_back(u) ; ++deg[u] , ++deg[v] ; } dfs(1,0) ; int six = ar.size() ; printf("%d\n",(six+1)/2) ; int mid = (six+1)/2 ; for(int i = 0 ; i < mid ; ++i) { if((i+mid)<six) printf("%d %d\n",ar[i],ar[i+mid]) ; else printf("%d %d\n",ar[i],ar[six-1]) ; } return 0 ; }

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

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