제출 #41211

#제출 시각아이디문제언어결과실행 시간메모리
41211wzyNetwork (BOI15_net)C++14
0 / 100
12 ms12460 KiB
#include <bits/stdc++.h> using namespace std; int n; vector<int> adj[500005]; int main(){ cin>>n; for(int i= 0 ; i < n - 1 ; i++){ int x ,y; cin>>x>>y; x-- , y--; adj[x].push_back(y); adj[y].push_back(x); } vector<int> tocreate; int lastv = -1; for(int i = 0 ; i < n; i++){ if(adj[i].size() == 1) tocreate.push_back(i); } vector<pair<int,int> > edges; while(!tocreate.empty()){ if(tocreate.size() == 1){ edges.push_back(pair<int,int>(lastv , tocreate.back())); break; } else{ int u = tocreate.back(); tocreate.pop_back(); int v = tocreate.back(); tocreate.pop_back(); lastv = v; edges.push_back(pair<int,int>(lastv,u)); } } cout<<edges.size()<<endl; for(int j = 0 ; j < edges.size() ; j++){ pair<int,int> v = edges[j]; cout<<v.first + 1 <<" " << v.second + 1 << endl; } }

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

net.cpp: In function 'int main()':
net.cpp:36:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int j = 0 ; j < edges.size() ; j++){
                    ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...