Submission #227998

#TimeUsernameProblemLanguageResultExecution timeMemory
227998quocnguyen1012Network (BOI15_net)C++14
0 / 100
5 ms384 KiB
#include <bits/stdc++.h>

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define ar array

using namespace std;
typedef long long ll;
typedef pair<int, int> ii;

const int maxn = 5e5 + 5;

int deg[maxn], N;
vector<int> leaf;

signed main(void)
{
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  #ifdef LOCAL
    freopen("A.INP", "r", stdin);
    freopen("A.OUT", "w", stdout);
  #endif // LOCAL
  cin >> N;
  for(int i = 1; i < N; ++i){
    int u, v; cin >> u >> v;
    deg[u]++; deg[v]++;
  }
  for(int i = 1; i <= N; ++i){
    if(deg[i] == 1) leaf.eb(i);
  }
  cout << (leaf.size() + 1) / 2 << '\n';
  int half = leaf.size() / 2;
  for(int i = 0; i <= (leaf.size() - 1) / 2; ++i)
    cout << leaf[i] << ' ' << leaf[i + half] << '\n';
}

Compilation message (stderr)

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