제출 #538944

#제출 시각아이디문제언어결과실행 시간메모리
538944Soul234Network (BOI15_net)C++14
100 / 100
482 ms47744 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; const ll MOD = 1e9+7; const int N = 5e5+5; int n; vector<int>leaf; vector<int>v[N]; void dfs(int s,int p){ if(v[s].size()==1){ leaf.push_back(s); } for(int i=0;i<v[s].size();i++){ if(v[s][i]!=p){ dfs(v[s][i],s); } } } int main() { ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr); int x,y; cin>>n; for(int i=0;i<n-1;i++){ cin>>x>>y; v[x].push_back(y); v[y].push_back(x); } dfs(1,-1); int k=(int)leaf.size(); if(k%2==0){ cout<<k/2<<"\n"; for(int i=0;i<k/2;i++){ cout<<leaf[i]<<" "<<leaf[i+k/2]<<"\n"; } }else{ cout<<k/2+1<<"\n"; for(int i=0;i<k/2;i++){ cout<<leaf[i]<<" "<<leaf[i+k/2+1]<<"\n"; } cout<<leaf[k/2]<<" "<<1; } return 0; }

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

net.cpp: In function 'void dfs(int, int)':
net.cpp:16:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   16 |  for(int i=0;i<v[s].size();i++){
      |              ~^~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...