Submission #862042

#TimeUsernameProblemLanguageResultExecution timeMemory
862042NeroZeinNetwork (BOI15_net)C++17
0 / 100
3 ms12124 KiB
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <math.h> #include <limits.h> #include <stack> #include <queue> #include <map> #include <set> #include <algorithm> #include <string> #include <functional> #include <vector> #include <numeric> #include <deque> #include <bitset> #include <iostream> using namespace std; typedef long long lint; typedef long double llf; typedef pair<int, int> pi; int n; vector<int> graph[500005]; vector<int> v; void dfs(int x, int p){ int cnt = 0; for(auto &i : graph[x]){ if(i == p) continue; dfs(i, x); cnt++; } if(cnt == 0) v.push_back(x); } int main(){ scanf("%d",&n); for(int i=0; i<n-1; i++){ int s, e; scanf("%d %d",&s,&e); graph[s].push_back(e); graph[e].push_back(s); } for(int i=1; i<=n; i++){ if(graph[i].size() != 1){ dfs(i, 0); break; } } printf("%d\n",(v.size() + 1) / 2); for(int i = 1; i < v.size(); i += 2){ printf("%d %d\n",v[i], v[i - 1]); } if (v.size() & 1) { cout << v[0] << ' ' << v.back() << '\n'; } }

Compilation message (stderr)

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