제출 #239826

#제출 시각아이디문제언어결과실행 시간메모리
239826kshitij_sodaniNetwork (BOI15_net)C++17
0 / 100
13 ms12032 KiB
#include <bits/stdc++.h> using namespace std; typedef int64_t llo; #define mp make_pair #define pb push_back #define a first #define b second int n; vector<int> adj[500001]; vector<int> kk; void dfs(int no,int par=-1){ for(auto j:adj[no]){ if(j!=par){ dfs(j,no); } } if(adj[no].size()==1){ kk.pb(no); } } int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); cin>>n; for(int i=0;i<n-1;i++){ int aa,bb; cin>>aa>>bb; adj[aa-1].pb(bb-1); adj[bb-1].pb(aa-1); } int r=0; for(int i=0;i<n;i++){ if(adj[i].size()>1){ r=i; } } dfs(r); cout<<((kk.size()+1)/2)<<endl; for(int i=0;i<kk.size()/2;i++){ cout<<kk[i]+1<<" "<<kk[kk.size()-i-1]+1<<endl; } if(kk.size()%2==1){ cout<<kk[kk.size()/2]+1<<" "<<r+1<<endl; } return 0; }

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

net.cpp: In function 'int main()':
net.cpp:44:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0;i<kk.size()/2;i++){
              ~^~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...