Submission #303966

#TimeUsernameProblemLanguageResultExecution timeMemory
303966HemimorNetwork (BOI15_net)C++14
100 / 100
1352 ms47916 KiB
#include <algorithm> #include <iostream> #include <iomanip> #include <numeric> #include <cassert> #include <vector> #include <cmath> #include <queue> #include <set> #include <map> #define syosu(x) fixed<<setprecision(x) using namespace std; typedef long long ll; typedef unsigned int uint; typedef unsigned long long ull; typedef pair<int,int> P; typedef pair<double,double> pdd; typedef pair<ll,ll> pll; typedef vector<int> vi; typedef vector<vi> vvi; typedef vector<double> vd; typedef vector<vd> vvd; typedef vector<ll> vl; typedef vector<vl> vvl; typedef vector<string> vs; typedef vector<P> vp; typedef vector<vp> vvp; typedef vector<pll> vpll; typedef pair<int,P> pip; typedef vector<pip> vip; const int inf=1<<29; const ll INF=1ll<<60; const double pi=acos(-1); const double eps=1e-8; const ll mod=998244353; const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1}; int n; vvi g; vi a; void dfs(int v,int p=0){ if(g[v].size()==1) a.push_back(v); for(auto u:g[v]) if(u!=p) dfs(u,v); } int main(){ cin>>n; g=vvi(n+1); for(int i=1;i<n;i++){ int u,v; cin>>u>>v; g[u].push_back(v); g[v].push_back(u); } dfs(1); int m=a.size(),sz=(m+1)/2; cout<<sz<<endl; for(int i=0;i<sz;i++) cout<<a[i]<<' '<<a[i+m/2]<<endl; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...