Submission #51138

#TimeUsernameProblemLanguageResultExecution timeMemory
51138faustaadpNetwork (BOI15_net)C++17
0 / 100
12 ms12264 KiB
#include<bits/stdc++.h> #define ll long long #define pb push_back #define mp make_pair #define fi first #define se second using namespace std; ll n,ta,tb,i,dg[505050],Vs,R; vector<ll> v[505050],V; void dfs(ll aa,ll bb) { //cout<<aa<<" "<<bb if(dg[aa]==1) V.pb(aa); ll ii; for(ii=0;ii<v[aa].size();ii++) if(v[aa][ii]!=bb) dfs(v[aa][ii],aa); } int main() { cin>>n; for(i=1;i<n;i++) { cin>>ta>>tb; v[ta].pb(tb); v[tb].pb(ta); dg[ta]++; dg[tb]++; } for(i=1;i<=n;i++) if(dg[i]>1) R=i; dfs(R,-1); Vs=V.size(); if(Vs%2==1) { V.pb(V[Vs-1]); Vs++; } cout<<Vs/2<<"\n"; for(i=0;i<Vs/2;i++) cout<<V[i]<<" "<<V[Vs-i-1]<<"\n"; }

Compilation message (stderr)

net.cpp: In function 'void dfs(long long int, long long int)':
net.cpp:16:13: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(ii=0;ii<v[aa].size();ii++)
           ~~^~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...