제출 #951406

#제출 시각아이디문제언어결과실행 시간메모리
951406Doncho_BonbonchoNetwork (BOI15_net)C++14
0 / 100
6 ms24152 KiB
#include <bits/stdc++.h> using namespace std; template< class T, class T2 > inline bool chkmin( T& a, const T2& b ){ return a > b ? a = b, 1 : 0; } template< class T, class T2 > inline bool chkmax( T& a, const T2& b ){ return a < b ? a = b, 1 : 0; } #ifndef LOCAL #define cerr if( false )cerr #endif #define out(x) #x << " = " << x << " " typedef long long ll; const int MAX_N = 1e6 + 42; const ll mod = 1e9 + 7; std::vector< int > v[MAX_N]; int main (){ #ifndef LOCAL std::ios_base::sync_with_stdio( false ); std::cin.tie( NULL ); std::cout.tie( NULL ); #endif int n; std::cin >> n; for( int i=0 ; i < n-1 ; i++ ){ int a, b; std::cin >> a >> b; a--; b--; v[a].push_back( b ); v[b].push_back( a ); } std::vector< int > leaves; for( int i=0 ; i < n ; i++ ){ if( v[i].size() == 1 ) leaves.push_back( i ); } srand( 116 ); std::random_shuffle( leaves.begin(), leaves.end() ); ll nas = leaves.size() / 2; if( leaves.size() & 1 ){ nas ++; std::cout << nas << endl; std::cout << leaves.back() +1 << " " << leaves[leaves.size()-2] +1 << endl; leaves.pop_back(); }else{ std::cout << nas << endl; } for( int i=0 ; i < leaves.size() ; i += 2 ){ std::cout << leaves[i] +1 << " " << leaves[ i +1 ] +1 << endl; } return 0; }

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

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