Submission #588562

#TimeUsernameProblemLanguageResultExecution timeMemory
588562M_WNetwork (BOI15_net)C++17
0 / 100
1 ms312 KiB
#include <bits/stdc++.h> using namespace std; vector<int> v; int deg[500001]; int main(){ int N; scanf("%d", &N); for(int i = 1, u, v; i < N; i++){ scanf("%d %d", &u, &v); deg[u]++; deg[v]++; } for(int i = 1; i <= N; i++){ if(deg[i] == 1) v.push_back(i); } queue<pair<int, int>> q; for(int i = 0; i + 1 < v.size(); i += 2){ q.push({v[i], v[i + 1]}); } if(v.size() % 2) q.push({v[v.size() - 1], 0}); printf("%d\n", q.size()); while(!q.empty()){ printf("%d %d\n", q.front().first, q.front().second); q.pop(); } }

Compilation message (stderr)

net.cpp: In function 'int main()':
net.cpp:16:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   16 |  for(int i = 0; i + 1 < v.size(); i += 2){
      |                 ~~~~~~^~~~~~~~~~
net.cpp:20:11: warning: format '%d' expects argument of type 'int', but argument 2 has type 'std::queue<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wformat=]
   20 |  printf("%d\n", q.size());
      |          ~^     ~~~~~~~~
      |           |           |
      |           int         std::queue<std::pair<int, int> >::size_type {aka long unsigned int}
      |          %ld
net.cpp:7:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    7 |  scanf("%d", &N);
      |  ~~~~~^~~~~~~~~~
net.cpp:9:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    9 |   scanf("%d %d", &u, &v);
      |   ~~~~~^~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...