Submission #476066

#TimeUsernameProblemLanguageResultExecution timeMemory
476066ZaZo_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; 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); } for(int i = 1 ; i <= n ; i++) { if(edges[i].size()==1) leaves.push_back(i); } 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; } if(leaves.back()==1&&edges[leaves.back()][0]==2) cout<<"3"; else if(leaves.back()==1) cout<<"2"; else cout<<"1"; } }

Compilation message (stderr)

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