Submission #923294

#TimeUsernameProblemLanguageResultExecution timeMemory
923294AiperiiiNetwork (BOI15_net)C++14
100 / 100
539 ms48612 KiB
#include <bits/stdc++.h> #define int long long #define ff first #define ss second #define pb push_back #define all(x) x.begin(),x.end() using namespace std; const int N=5e5+5; vector <int> g[N]; vector <int> lf; void dfs(int v,int p){ if(g[v].size()==1)lf.pb(v); for(auto to : g[v]){ if(to!=p){ dfs(to,v); } } } signed main(){ ios_base::sync_with_stdio(); cin.tie(0);cout.tie(0); int n;cin>>n; for(int i=0;i<n-1;i++){ int u,v; cin>>u>>v; g[u].pb(v); g[v].pb(u); } dfs(1,0); cout<<(lf.size()+1)/2<<"\n"; for(int i=0;i<(lf.size()+1)/2;i++){ cout<<lf[i]<<" "<<lf[i+lf.size()/2]<<"\n"; } }

Compilation message (stderr)

net.cpp: In function 'int main()':
net.cpp:32:17: 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]
   32 |    for(int i=0;i<(lf.size()+1)/2;i++){
      |                ~^~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...