Submission #939078

#TimeUsernameProblemLanguageResultExecution timeMemory
939078ezzzayNetwork (BOI15_net)C++14
100 / 100
650 ms58084 KiB
#include<bits/stdc++.h> using namespace std; #define int long long #define ff first #define ss second #define pb push_back const int N=5e5+5; bool vis[N]; vector<int>v[N]; vector<pair<int,int>>rts; vector<int>vec; void dfs(int a, int p=-1){ if(v[a].size()==1)vec.pb(a); for(auto b:v[a]){ if(b!=p){ dfs(b,a); } } } signed main(){ int n; cin>>n; for(int i=1;i<n;i++){ int a,b; cin>>a>>b; v[a].pb(b); v[b].pb(a); rts.pb({a,b}); } dfs(1); cout<<vec.size()/2+vec.size()%2<<endl; for(int i=0;i<(vec.size()+1)/2;i++){ cout<<vec[i]<<" "<<vec[i+vec.size()/2]<<endl; } }

Compilation message (stderr)

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