제출 #298510

#제출 시각아이디문제언어결과실행 시간메모리
298510jbroeksteegNetwork (BOI15_net)C++14
100 / 100
853 ms47728 KiB
#include <iostream> #include <climits> #include <numeric> #include <cassert> #include <algorithm> #include <queue> #include <map> #include <stack> #include <set> #include <vector> #include <array> #include <memory> #define IN(a,b) (a.find(b) != a.end()) #define p(a,b) make_pair(a,b) #define readVec(a) for (int __i = 0; __i<(int)a.size();__i++){cin>>a[__i];} // jimjam template<typename T> void pMin(T &a, T b) {if (b<a){a=b;}} template<typename T> void pMax(T &a, T b) {if (b>a){a=b;}} template<typename T> std::ostream& operator<<(std::ostream& os, const std::vector<T>& c); template<typename A, typename B> std::ostream& operator<<(std::ostream& os, const std::pair<A,B>& c) {std::cout << "(" << c.first << ", " << c.second << ")";return os;} template<typename T> std::ostream& operator<<(std::ostream& os, const std::vector<T>& c) { if (c.size() == 0) {os << "{}"; return os;} os << "{" << c[0]; for (int i = 1; i < (int)c.size(); i++) {os <<", "<<c[i];} os << "}"; return os; } const int inf = 2e9; #define MAXN 500001 using namespace std; vector<int> adj[MAXN]; vector<int> leaves; void dfs(int c, int p=-1) { if (adj[c].size()==1) { leaves.push_back(c); } for (int i: adj[c]) { if (i!=p) { dfs(i,c); } } } int main() { ios::sync_with_stdio(0); cin.tie(0); int n; cin >> n; for (int i = 0; i < n-1; i++) { int a, b; cin >> a >> b; adj[a].push_back(b); adj[b].push_back(a); } for (int i = 1; i <= n; i++) { if (adj[i].size()>1) { dfs(i); break; } } // cout << leaves.size()/2 + leaves.size()%2 << "\n"; int cnt=0; while (cnt<leaves.size()) { if (cnt+1==leaves.size()) { // cout << leaves[cnt] << " 1\n"; cnt++; } else { // cout << leaves[cnt] << " " << leaves[cnt+1] << "\n"; cnt+=2; } } cout << leaves.size()/2 + leaves.size()%2 << endl; for (int i = 0; i < leaves.size()/2+leaves.size()%2; i++) { cout << leaves[i] << " " << leaves[i + leaves.size()/2] << endl; //if (other<i) break; } return 0; }

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

net.cpp: In function 'int main()':
net.cpp:75:12: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   75 |  while (cnt<leaves.size()) {
      |         ~~~^~~~~~~~~~~~~~
net.cpp:76:12: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   76 |   if (cnt+1==leaves.size()) {
      |       ~~~~~^~~~~~~~~~~~~~~
net.cpp:86:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   86 |  for (int i = 0; i < leaves.size()/2+leaves.size()%2; i++) {
      |                  ~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...