Submission #824330

#TimeUsernameProblemLanguageResultExecution timeMemory
824330irmuunNetwork (BOI15_net)C++17
100 / 100
359 ms70976 KiB
#include<bits/stdc++.h> using namespace std; #define ll long long #define pb push_back #define ff first #define ss second #define all(s) s.begin(),s.end() #define rall(s) s.rbegin(),s.rend() int main(){ ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); ll n; cin>>n; vector<ll>adj[n+1]; for(ll i=1;i<n;i++){ ll a,b; cin>>a>>b; adj[a].pb(b); adj[b].pb(a); } ll mx=0,ind; for(ll i=1;i<=n;i++){ if(adj[i].size()>mx){ mx=adj[i].size(); ind=i; } } vector<ll>ord; function <void(ll,ll)> dfs=[&](ll x,ll p){ if(adj[x].size()==1){ ord.pb(x); } for(auto y:adj[x]){ if(y!=p){ dfs(y,x); } } }; for(auto x:adj[ind]){ dfs(x,ind); } if(ord.size()%2==1){ ord.pb(ord[0]); } ll sz=ord.size(); cout<<sz/2<<"\n"; for(ll i=0;i<sz/2;i++){ cout<<ord[i]<<' '<<ord[i+sz/2]<<"\n"; } }

Compilation message (stderr)

net.cpp: In function 'int main()':
net.cpp:25:25: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
   25 |         if(adj[i].size()>mx){
      |            ~~~~~~~~~~~~~^~~
net.cpp:23:13: warning: 'ind' may be used uninitialized in this function [-Wmaybe-uninitialized]
   23 |     ll mx=0,ind;
      |             ^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...