Submission #113780

#TimeUsernameProblemLanguageResultExecution timeMemory
113780MercenaryNetwork (BOI15_net)C++14
0 / 100
12 ms12032 KiB
#include<bits/stdc++.h> using namespace std; #define taskname "A" #define pb push_back #define mp make_pair #ifndef LOCAL #define cerr if(0)cout #endif typedef long double ld; typedef long long ll; typedef pair<int,int> ii; const int maxn = 5e5 + 6; int n , m; vector<int> leaf , adj[maxn]; void dfs(int u , int v){ if(adj[u].size() == 1){ leaf.pb(u); } for(int c : adj[u]){ if(c != v)dfs(c , u); } } void enter(){ cin >> n; for(int i = 1 ; i < n ; ++i){ int u , v;cin >> u >> v; adj[u].pb(v); adj[v].pb(u); } } int main() { ios_base::sync_with_stdio(0); cin.tie(0); if(fopen(taskname".INP","r")){ freopen(taskname".INP", "r",stdin); freopen(taskname".OUT", "w",stdout); } enter(); int root = 0; for(int i = 1 ; i <= n ; ++i){ if(adj[i].size() > 1){ dfs(i , 0); root = i; break; } } if(leaf.size() % 2){ leaf.pb(leaf.back()); } cout << leaf.size() / 2 << '\n'; for(int i = 0 ; i < leaf.size() / 2 ; ++i){ cout << leaf[i] << " " << leaf[leaf.size() - i - 1] << '\n'; } }

Compilation message (stderr)

net.cpp: In function 'int main()':
net.cpp:57:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i = 0 ; i < leaf.size() / 2 ; ++i){
                     ~~^~~~~~~~~~~~~~~~~
net.cpp:45:9: warning: variable 'root' set but not used [-Wunused-but-set-variable]
     int root = 0;
         ^~~~
net.cpp:41:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   freopen(taskname".INP", "r",stdin);
   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
net.cpp:42:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   freopen(taskname".OUT", "w",stdout);
   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...