Submission #476092

#TimeUsernameProblemLanguageResultExecution timeMemory
476092ZaZo_Network (BOI15_net)C++14
63 / 100
3 ms2764 KiB
#include <bits/stdc++.h> #define HID ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); #define int long long #define all(v) v.begin(),v.end() const int N = 50005 , INF = 1e15 , MOD=1000000006; using namespace std; int n ; vector<int>edges[N]; vector<int>leaves; void dfs(int node , int par) { if(edges[node].size()==1) leaves.push_back(node); for(auto x : edges[node]) if(x!=par) dfs(x,node); } int32_t main() { HID cin>>n; for(int i = 0 ; i < n-1 ; i++) { int u , v; cin >> u >> v; edges[u].push_back(v); edges[v].push_back(u); } dfs(1,-1); cout<<(leaves.size()+1)/2<<endl; if(leaves.size()%2==0) { for(int i = 0 ; i < leaves.size()/2 ; i++) cout<<leaves[i]<<" "<<leaves[leaves.size()/2+i]<<endl; } else { for(int i = 0 ; i < leaves.size()/2 ; i++) { if(i==leaves.size()-1) break; cout<<leaves[i]<<" "<<leaves[leaves.size()/2+i]<<endl; } cout<<leaves.back()<<" "; for(int i = 1 ; i <= n ; i++) { if(i!=leaves.back()&&i!=edges[leaves.back()][0]) { cout<<i<<endl; break; } } } }

Compilation message (stderr)

net.cpp: In function 'int32_t main()':
net.cpp:31:23: 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(int i = 0 ; i < leaves.size()/2 ; i++)
      |                     ~~^~~~~~~~~~~~~~~~~
net.cpp:36:23: 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]
   36 |     for(int i = 0 ; i < leaves.size()/2 ; i++)
      |                     ~~^~~~~~~~~~~~~~~~~
net.cpp:38:11: 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]
   38 |       if(i==leaves.size()-1)  break;
      |          ~^~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...