Submission #81555

#TimeUsernameProblemLanguageResultExecution timeMemory
81555arman_ferdousNetwork (BOI15_net)C++17
0 / 100
12 ms12180 KiB
#include <bits/stdc++.h> using namespace std; const int N = 5e5+10; int n, d[N]; vector<int> g[N], leaf; int main() { 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); d[u]++, d[v]++; } for(int i = 1; i <= n; i++) if(d[i] == 1) leaf.push_back(i); random_shuffle(leaf.begin(),leaf.end()); random_shuffle(leaf.begin(),leaf.end()); int sz = leaf.size(); printf("%d\n", (int)ceil(sz/2.)); for(int i = 0; i < sz; i+=2) { if(i+1 < sz) printf("%d %d\n", leaf[i], leaf[i+1]); else printf("%d %d\n", leaf[i], leaf[0]); } return 0; }

Compilation message (stderr)

net.cpp: In function 'int main()':
net.cpp:9:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &n);
  ~~~~~^~~~~~~~~~
net.cpp:11:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   int u, v; scanf("%d %d", &u, &v);
             ~~~~~^~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...