제출 #524745

#제출 시각아이디문제언어결과실행 시간메모리
524745perchutsNetwork (BOI15_net)C++17
0 / 100
7 ms12060 KiB
#include <bits/stdc++.h> #define maxn (int)(1e5+51) #define all(x) x.begin(), x.end() #define sz(x) (int) x.size() #define endl '\n' #define ll long long #define pb push_back #define ull unsigned long long #define ii pair<int,int> #define iii tuple<int,int,int> #define inf 2000000001 #define mod 1000000007 //998244353 #define _ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); using namespace std; template<typename X, typename Y> bool ckmin(X& x, const Y& y) { return (y < x) ? (x=y,1):0; } template<typename X, typename Y> bool ckmax(X& x, const Y& y) { return (x < y) ? (x=y,1):0; } vector<int>g[5*maxn]; vector<int>leaves; void dfs(int x,int p){ int ok = 0; for(auto v:g[x]){ if(v==p)continue; ok = 1; dfs(v,x); } if(!ok||(x==1&&sz(g[x])==1))leaves.pb(x); } int main(){_ int n;cin>>n; for(int i=1;i<n;i++){ int a,b;cin>>a>>b; g[a].pb(b); g[b].pb(a); } dfs(1,1); int x = sz(leaves); cout<<(x+1)/2<<endl; for(int i=0;i+1<x;i+=2)cout<<leaves[i]<<" "<<leaves[i+1]<<endl; if(x&1){ cout<<leaves[0]<<" "<<leaves[x-1]<<endl; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...