Submission #503951

#TimeUsernameProblemLanguageResultExecution timeMemory
503951goodluck2020Network (BOI15_net)C++14
0 / 100
2 ms2640 KiB
#include <bits/stdc++.h> #define task "BOI15_net" #define sz(X) ((int)X.size()) using namespace std; const int N = 1e5 + 5; int n; vector < int > adj[N], Leaf; vector < pair < int , int > > res; void DFS(int u, int par) { if(sz(adj[u]) == 1) Leaf.push_back(u); for(int v : adj[u]) if(v != par) DFS(v, u); } int main() { 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].push_back(v); adj[v].push_back(u); } DFS(1, 0); for(int i = 1; i < sz(Leaf); i += 2) res.push_back({Leaf[i], Leaf[i - 1]}); if(sz(Leaf) % 2 == 1) res.push_back({1, Leaf.back()}); cout << sz(res) << '\n'; for(auto it : res) cout << it.first << " " << it.second << '\n'; }

Compilation message (stderr)

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