Submission #69457

#TimeUsernameProblemLanguageResultExecution timeMemory
69457kingpig9Network (BOI15_net)C++11
0 / 100
15 ms12136 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pii; #define debug(...) fprintf(stderr, __VA_ARGS__) //#define debug(...) #define all(v) (v).begin(), (v).end() #define fillchar(a, s) memset((a), (s), sizeof(a)) #define fi first #define se second int N; vector<int> adj[500010]; vector<int> leaves; void dfs (int x, int p) { if (adj[x].size() == 1) { leaves.push_back(x); } for (int y : adj[x]) { if (y != p) { dfs(y, x); } } } int main() { scanf("%d", &N); for (int i = 1; i < N; i++) { int x, y; scanf("%d %d", &x, &y); adj[x].push_back(y); adj[y].push_back(x); } int root = 1; while (adj[root].size() == 1) { root++; } dfs(root, -1); vector<pii> ans; for (int i = 0, j = leaves.size() - 1; i < j; i++, j--) { ans.push_back({leaves[i], leaves[j]}); } if (leaves.size() % 2) { ans.push_back({leaves[leaves.size() / 2], leaves[0]}); } printf("%lu\n", ans.size()); for (pii p : ans) { printf("%d %d\n", p.fi, p.se); } }

Compilation message (stderr)

net.cpp: In function 'int main()':
net.cpp:30:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &N);
  ~~~~~^~~~~~~~~~
net.cpp:33:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d", &x, &y);
   ~~~~~^~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...