제출 #910027

#제출 시각아이디문제언어결과실행 시간메모리
910027PetrixNetwork (BOI15_net)C++17
0 / 100
1 ms2396 KiB
#include <iostream> #include <vector> #include <algorithm> using namespace std; vector<vector<int>> v; int frunza[500001],p[500001]; vector<pair<int,int>> rasp; int cnt; void dfs(int parinte,int nod){ p[nod]=cnt;cnt++; int aux=0,i; for(i=0;i<v[nod].size();i++){ if(v[nod][i]!=parinte){ aux++;dfs(nod,v[nod][i]); } } if(!aux) frunza[nod]=1; } int main() { int n,i,a,b;cnt=0; cin>>n;v.resize(n+1); for(i=0;i<n-1;i++){ cin>>a>>b; v[a].push_back(b); v[b].push_back(a); } dfs(-1,1); for(i=1;i<=n;i++){ if(i==1 && v[1].size()==1){ rasp.push_back({p[i],i}); }else if(frunza[i]==1){ rasp.push_back({p[i],i}); } } cout<<(rasp.size()+1)/2<<"\n"; sort(rasp.begin(),rasp.end()); for(i=0;i<(rasp.size()+1)/2;i++){ cout<<rasp[i+1].second<<" "<<rasp[i+(rasp.size()/2)].second<<"\n"; } return 0; }

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

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