Submission #405191

#TimeUsernameProblemLanguageResultExecution timeMemory
405191T0p_Network (BOI15_net)C++14
Compilation error
0 ms0 KiB
#include <bits/stdc++.h> using namespace std; int sz; vector<int> g[500005], leaf; void dfs(int u, int p) { if(g[u].size() == 1) leaf.push_back(u), sz++; for(auto x : g[u]) if(x != p) dfs(x, u); } int main() { int n; scanf(" %d",&n); for(int i=1 ; i<n ; i++) { int u, v; scanf(" %d %d",&u,&v); g[u].push_back(v), g[v].push_back(u); } dfs(1, 0); printf("%d\n",(sz+1)/2); for(int i=0 ; i<sz ; i+=2) printf("%d %d\n",v[i],v[i+1]); if(sz%2) printf("%d %d\n",v[sz-1],v[0]); return 0; }

Compilation message (stderr)

net.cpp: In function 'int main()':
net.cpp:26:20: error: 'v' was not declared in this scope
   26 |   printf("%d %d\n",v[i],v[i+1]);
      |                    ^
net.cpp:27:28: error: 'v' was not declared in this scope
   27 |  if(sz%2) printf("%d %d\n",v[sz-1],v[0]);
      |                            ^
net.cpp:16:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   16 |  scanf(" %d",&n);
      |  ~~~~~^~~~~~~~~~
net.cpp:20:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   20 |   scanf(" %d %d",&u,&v);
      |   ~~~~~^~~~~~~~~~~~~~~~