Submission #291584

#TimeUsernameProblemLanguageResultExecution timeMemory
291584FischerNetwork (BOI15_net)C++14
0 / 100
9 ms12032 KiB
#include <bits/stdc++.h> using namespace std; const int maxn = 5e5 + 10; vector<int> g[maxn]; int n; using ii = pair<int, int>; int dfs(vector<ii>& edges, int x, int p=0) { int node = g[x].size() == 1 ? x : -1; for (int v : g[x]) { if (v==p) continue; int u = dfs(edges, v, x); if (node == -1) node = u; else if (u != -1) edges.emplace_back(node, u), node = -1; } return node; } int main() { scanf("%d", &n); for (int i=0; i<n-1; ++i) { int a, b; scanf("%d%d", &a, &b); g[a].emplace_back(b); g[b].emplace_back(a); } vector<ii> edges; for (int i=1; i<=n; ++i) { if (g[i].size()>1) { int extra = dfs(edges, i); if (extra != -1) edges.emplace_back(extra, i); break; } } cout << edges.size() << endl; for (auto e : edges) cout << e.first << " " << e.second << '\n'; return 0; }

Compilation message (stderr)

net.cpp: In function 'int main()':
net.cpp:21:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   21 |     scanf("%d", &n);
      |     ~~~~~^~~~~~~~~~
net.cpp:24:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   24 |         scanf("%d%d", &a, &b);
      |         ~~~~~^~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...