Submission #24512

#TimeUsernameProblemLanguageResultExecution timeMemory
24512BruteforcemanNetwork (BOI15_net)C++11
0 / 100
3 ms15696 KiB
#include "bits/stdc++.h" using namespace std; int deg[500010]; deque <int> nodes; vector <int> g[500010]; void dfs(int x, int par) { if(deg[x] == 1) { nodes.push_back(x); } for(auto i : g[x]) { if(i - par) { dfs(i, x); } } } int main(int argc, char const *argv[]) { int n; scanf("%d", &n); for(int i = 1; i < n; i++) { int p, q; scanf("%d %d", &p, &q); ++deg[p]; ++deg[q]; g[p].push_back(q); g[q].push_back(p); } for(int i = 1; i <= n; i++) { if(deg[i] != 1) { dfs(i, 0); break; } } printf("%d\n", (nodes.size() + 1) >> 1); int good = nodes.front(); while(nodes.size() > 1) { int p = nodes.front(); int q = nodes.back(); nodes.pop_front(); nodes.pop_back(); printf("%d %d\n", p, q); } if(!nodes.empty()) { printf("%d %d\n", good, nodes.front()); } return 0; }

Compilation message (stderr)

net.cpp: In function 'int main(int, const char**)':
net.cpp:36:40: warning: format '%d' expects argument of type 'int', but argument 2 has type 'std::deque<int>::size_type {aka long unsigned int}' [-Wformat=]
  printf("%d\n", (nodes.size() + 1) >> 1);
                                        ^
net.cpp:21:17: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &n);
                 ^
net.cpp:24:25: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d", &p, &q);
                         ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...