제출 #614133

#제출 시각아이디문제언어결과실행 시간메모리
614133sword060Network (BOI15_net)C++17
0 / 100
8 ms12160 KiB
#include <bits/stdc++.h> using namespace std; int x; vector<int>v[500005]; vector<pair<int,int>>ans; set<pair<int,int>> dfs(int i,int aa,int c,int p=-1){ set<pair<int,int>>ret; if(v[i].size()==1)ret.insert({c,i}); for(auto j:v[i]){ if(j==p)continue; set<pair<int,int>>lol=dfs(j,aa,c+1,i); for(auto k:lol)ret.insert({k.first,k.second}); } if(i==aa){ vector<int>vv; for(auto [j,r]:ret)vv.push_back(r); for(int j=0;j<vv.size()/2;j++)ans.push_back({vv[j],vv[(int)vv.size()-j-1]}); if((int)vv.size()%2){ int m1=vv[vv.size()/2]; if(m1!=i)ans.push_back({vv[m1],vv[i]}); else ans.push_back({vv[m1],vv[x]}); } } return ret; } int main(){ ios::sync_with_stdio(0); cin.tie(0); cin>>x; for(int i=1;i<=x-1;i++){ int l,r;cin>>l>>r; v[l].push_back(r); v[r].push_back(l); } for(int i=1;i<=x;i++)if((int)v[i].size()==1){dfs(i,i,0,i);break;} cout<<ans.size()<<"\n"; for(auto [l,r]:ans)cout<<l<<" "<<r<<endl; return 0; }

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

net.cpp: In function 'std::set<std::pair<int, int> > dfs(int, int, int, int)':
net.cpp:17:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   17 |     for(int j=0;j<vv.size()/2;j++)ans.push_back({vv[j],vv[(int)vv.size()-j-1]});
      |                 ~^~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...