Submission #1064032

#TimeUsernameProblemLanguageResultExecution timeMemory
1064032manhlinh1501Network (BOI15_net)C++17
0 / 100
5 ms12140 KiB
#include <bits/stdc++.h> using namespace std; using i64 = long long; const int MAXN = 5e5 + 5; using pii = pair<int, int>; int N; vector<int> adj[MAXN]; vector<int> leaves; void DFS(int u, int p) { for(int v : adj[u]) { if(v == p) continue; DFS(v, u); } if(adj[u].size() == 1) leaves.emplace_back(u); } signed main() { #define TASK "code" if (fopen(TASK ".inp", "r")) { freopen(TASK ".inp", "r", stdin); freopen(TASK ".out", "w", stdout); } ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> N; for(int i = 1; i < N; i++) { int u, v; cin >> u >> v; adj[u].emplace_back(v); adj[v].emplace_back(u); } for(int i = 1; i <= N; i++) { if(adj[i].size() > 1) { DFS(i, 0); break; } } if(leaves.size() == 1) return cout << 0, 0; int k = leaves.size() / 2; cout << (leaves.size() + 1) / 2 << "\n"; for(int i = 0; i < k; i++) cout << leaves[i] << " " << leaves[i + k] << "\n"; if(leaves.size() % 2) cout << leaves[0] << " " << leaves[k] << "\n"; return (0 ^ 0); }

Compilation message (stderr)

net.cpp: In function 'int main()':
net.cpp:23:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   23 |         freopen(TASK ".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
net.cpp:24:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   24 |         freopen(TASK ".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...