Submission #476078

#TimeUsernameProblemLanguageResultExecution timeMemory
476078ZaZo_Network (BOI15_net)C++14
0 / 100
1 ms1484 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; int vis[N]={0}; void dfs(int node) { if(edges[node].size()==1) leaves.push_back(node); vis[node]=1; for(auto x : edges[node]) if(!vis[x]) dfs(x); } 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); cout<<(leaves.size()+1)/2<<endl; if(leaves.size()%2==0) { for(int i = 0 ; i < leaves.size() ; i+=2) { cout<<leaves[i]<<" "<<leaves[i+1]<<endl; } } else { for(int i = 0 ; i < leaves.size() ; i+=2) { if(i==leaves.size()-1) break; cout<<leaves[i]<<" "<<leaves[i+1]<<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:33: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]
   33 |     for(int i = 0 ; i < leaves.size() ; i+=2)
      |                     ~~^~~~~~~~~~~~~~~
net.cpp:40: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]
   40 |     for(int i = 0 ; i < leaves.size() ; i+=2)
      |                     ~~^~~~~~~~~~~~~~~
net.cpp:42: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]
   42 |       if(i==leaves.size()-1)  break;
      |          ~^~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...