제출 #397314

#제출 시각아이디문제언어결과실행 시간메모리
397314BitmaskingNetwork (BOI15_net)C++14
100 / 100
452 ms52880 KiB
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; using namespace std; #define f(i,a,b) for( ll i = a; i < b ; i++ ) #define af(i,a,b) for( ll i = a; i >= b ; i--) #define rep(i,a,b,k) for(ll i = a; i < b ; i+= k ) #define arep(i,a,b,k) for( ll i = a; i >= b ; i-= k) #define ones(ini) (ll) __builtin_popcountll(x) #define todo(y,val) all_of(all(y),[&val](ll x) {return (x == ((ll)val));}) #define nada(y,val) none_of(all(y),[&val](ll x) {return (x == ((ll)val));}) #define algu(y,val) any_of(all(y),[&val](ll x) {return (x == ((ll)val));}) #define cuantos(a,x) count(all(a),x) #define fs first #define sc second #define pb push_back #define po pop_back #define sz(a) (ll) a.size() #define all(a) a.begin(), a.end() #define sor(a) sort( a.begin(), a.end() ) #define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0) #define ller ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr) #define watch(x) cout << (#x) << " is " << (x) <<"\n" #define test ll deftestcases;cin>>deftestcases;while(deftestcases--) #define PI acos(-1) using namespace std; typedef long long ll; typedef long double ld; typedef pair<ll,ll> ii; typedef vector<ll> vi; typedef vector<ii> vii; template<class T> using ordered_set =tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update> ; const ll inf = 2e9; const ll mod = 1e9+7; const ll MAX = 5e5+10; vi adj[MAX]; vi hojas; void dfs(ll u,ll par){ for(auto v : adj[u]){ if(v!=par) dfs(v,u); } if(sz(adj[u])==1) hojas.pb(u); } int main(){ fastio; ll n;cin>>n; f(i,0,n-1){ ll u,v; cin>>u>>v; adj[u].pb(v); adj[v].pb(u); } dfs(1,0); n = sz(hojas); cout<<(n + n%2)/2<<"\n"; f(i,0,n/2) cout<<hojas[i]<<" "<<hojas[n/2+i]<<"\n"; if(n&1) cout<<hojas[0]<<" "<<hojas[n-1]<<"\n"; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...