제출 #404654

#제출 시각아이디문제언어결과실행 시간메모리
404654Aryan_RainaNetwork (BOI15_net)C++14
100 / 100
504 ms57184 KiB
#include <bits/stdc++.h>
using namespace std; 

#define int int64_t
#define ld long double
#define ar array

const int INF = 1e17;
const int MOD = 1e9+7;

int32_t main() {
   ios_base::sync_with_stdio(0);
   cin.tie(0); cout.tie(0);

   int N; cin >> N;
   vector<int> g[N];
   for (int i = 0; i < N - 1; i++) {
      int a, b; cin >> a >> b; --a, --b;
      g[a].push_back(b); g[b].push_back(a);
   }

   vector<int> leaves;
   function<void(int,int)> dfs = [&](int u, int pu) {
      if (g[u].size() == 1) leaves.push_back(u);
      for (int v : g[u]) if (v != pu) dfs(v, u);
   };

   // leaves are now sorted in tout order
   dfs(0, 0);

   int dif = (leaves.size() + 1) / 2;
   cout << dif << '\n';

   for (int i = 0; i < leaves.size()/2; i++)
      cout << leaves[i] + 1 << ' ' << leaves[i + dif] + 1 << '\n';

   if (leaves.size() & 1) 
      cout << leaves[leaves.size()/2] + 1 << ' ' << leaves[0] + 1<< '\n';
}  
 

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

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