제출 #533815

#제출 시각아이디문제언어결과실행 시간메모리
533815groshiNetwork (BOI15_net)C++17
100 / 100
359 ms47672 KiB
#include<iostream> #include<vector> using namespace std; struct wi{ vector<int> Q; }*w; vector<int> mam; void dfs(int x,int ojc) { if(w[x].Q.size()==1) mam.push_back(x); for(int i=0;i<w[x].Q.size();i++) { int pom=w[x].Q[i]; if(pom==ojc) continue; dfs(pom,x); } } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n,x,y; cin>>n; w=new wi[n+3]; for(int i=1;i<n;i++) { cin>>x>>y; w[x].Q.push_back(y); w[y].Q.push_back(x); } for(int i=1;i<=n;i++) { if(w[i].Q.size()>1) { dfs(i,0); break; } } cout<<(mam.size()+1)/2<<"\n"; for(int i=0;i<(mam.size()+1)/2;i++) cout<<mam[i]<<" "<<mam[i+mam.size()/2]<<"\n"; return 0; }

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

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