Submission #828291

#TimeUsernameProblemLanguageResultExecution timeMemory
828291vjudge1Network (BOI15_net)C++14
100 / 100
366 ms60220 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define vi vector<ll> #define pi pair<ll,ll> #define fi first #define se second #define gcd __gcd #define mset(a,v) memset(a, v, sizeof(a)) #define endl '\n' const int N = 1e6 + 5,LOG = 27; const ll MOD = 1e9 + 7,INF = 1e9; ll n; vector<ll>g[N]; vector<ll>leaf; bool vis[N]; void dfs(ll u,ll p = 0){ if(g[u].size() == 1)leaf.push_back(u); for(ll &v : g[u]) if(v != p) dfs(v,u); } void solve(){ cin>>n; for(ll i = 1;i < n;++i){ ll u,v; cin>>u>>v; g[u].push_back(v); g[v].push_back(u); } dfs(1); cout<<(leaf.size() + 1)/2<<endl; for(ll i = 0;2*i < leaf.size();++i) cout<<leaf[i]<<" "<<leaf[i + leaf.size()/2]<<endl; } signed main(){ cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(false); ll t = 1; //cin>>t; while(t--) solve(); cerr << endl << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n"; }

Compilation message (stderr)

net.cpp: In function 'void solve()':
net.cpp:31:22: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   31 |     for(ll i = 0;2*i < leaf.size();++i)
      |                  ~~~~^~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...