Submission #1064030

#TimeUsernameProblemLanguageResultExecution timeMemory
1064030manhlinh1501Network (BOI15_net)C++17
0 / 100
6 ms12124 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) { if(adj[u].size() == 1) { leaves.emplace_back(u); return void(0); } for(int v : adj[u]) { if(v == p) continue; DFS(v, 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:25:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   25 |         freopen(TASK ".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
net.cpp:26:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   26 |         freopen(TASK ".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...