Submission #1032556

#TimeUsernameProblemLanguageResultExecution timeMemory
1032556vjudge1Network (BOI15_net)C++17
0 / 100
7 ms12124 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define ld long double #define pii pair<int, int> #define pll pair<ll, ll> #define pld pair<ld, ld> #define pb push_back #define fi first #define se second #define debug(x) cout << #x << " => " << x << endl #define all(x) x.begin(),x.end() vector<int> adj[500010]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n;cin>>n; for(int i=1;i<n;i++) { int u,v;cin>>u>>v; adj[u].pb(v); adj[v].pb(u); } vector<int> v; for(int i=1;i<=n;i++) if(adj[i].size()==1) v.pb(i); vector<pii> ans; for(int i=0;i<v.size()-1;i+=2) { ans.pb({v[i],v[i+1]}); } if(v.size()&1) for(int i=1;i<=n;i++) { if(adj[v.back()].back()!=i && i!=v.back()) { ans.pb({v.back(),i}); break; } } cout<<ans.size()<<'\n'; for(auto i : ans) cout<<i.fi<<' '<<i.se<<'\n'; return 0; }

Compilation message (stderr)

net.cpp: In function 'int main()':
net.cpp:31:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   31 |  for(int i=0;i<v.size()-1;i+=2)
      |              ~^~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...