Submission #397314

# Submission time Handle Problem Language Result Execution time Memory
397314 2021-05-01T21:48:16 Z Bitmasking Network (BOI15_net) C++14
100 / 100
452 ms 52880 KB
#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 time Memory Grader output
1 Correct 7 ms 11980 KB Output is correct
2 Correct 8 ms 12060 KB Output is correct
3 Correct 7 ms 11980 KB Output is correct
4 Correct 7 ms 11980 KB Output is correct
5 Correct 7 ms 11980 KB Output is correct
6 Correct 7 ms 11980 KB Output is correct
7 Correct 7 ms 12060 KB Output is correct
8 Correct 7 ms 12060 KB Output is correct
9 Correct 8 ms 11980 KB Output is correct
10 Correct 8 ms 11980 KB Output is correct
11 Correct 8 ms 12060 KB Output is correct
12 Correct 7 ms 12004 KB Output is correct
13 Correct 7 ms 11980 KB Output is correct
14 Correct 7 ms 11980 KB Output is correct
15 Correct 7 ms 12060 KB Output is correct
16 Correct 7 ms 11980 KB Output is correct
17 Correct 7 ms 11980 KB Output is correct
18 Correct 7 ms 12060 KB Output is correct
19 Correct 7 ms 12060 KB Output is correct
20 Correct 7 ms 11980 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 11980 KB Output is correct
2 Correct 8 ms 12060 KB Output is correct
3 Correct 7 ms 11980 KB Output is correct
4 Correct 7 ms 11980 KB Output is correct
5 Correct 7 ms 11980 KB Output is correct
6 Correct 7 ms 11980 KB Output is correct
7 Correct 7 ms 12060 KB Output is correct
8 Correct 7 ms 12060 KB Output is correct
9 Correct 8 ms 11980 KB Output is correct
10 Correct 8 ms 11980 KB Output is correct
11 Correct 8 ms 12060 KB Output is correct
12 Correct 7 ms 12004 KB Output is correct
13 Correct 7 ms 11980 KB Output is correct
14 Correct 7 ms 11980 KB Output is correct
15 Correct 7 ms 12060 KB Output is correct
16 Correct 7 ms 11980 KB Output is correct
17 Correct 7 ms 11980 KB Output is correct
18 Correct 7 ms 12060 KB Output is correct
19 Correct 7 ms 12060 KB Output is correct
20 Correct 7 ms 11980 KB Output is correct
21 Correct 7 ms 11980 KB Output is correct
22 Correct 8 ms 12108 KB Output is correct
23 Correct 7 ms 12108 KB Output is correct
24 Correct 8 ms 12196 KB Output is correct
25 Correct 8 ms 12108 KB Output is correct
26 Correct 8 ms 12108 KB Output is correct
27 Correct 8 ms 12184 KB Output is correct
28 Correct 8 ms 12072 KB Output is correct
29 Correct 8 ms 12108 KB Output is correct
30 Correct 9 ms 11980 KB Output is correct
31 Correct 8 ms 12108 KB Output is correct
32 Correct 8 ms 11980 KB Output is correct
33 Correct 7 ms 12060 KB Output is correct
34 Correct 7 ms 11980 KB Output is correct
35 Correct 7 ms 12064 KB Output is correct
36 Correct 7 ms 12060 KB Output is correct
37 Correct 7 ms 12028 KB Output is correct
38 Correct 7 ms 12108 KB Output is correct
39 Correct 7 ms 12060 KB Output is correct
40 Correct 8 ms 11980 KB Output is correct
41 Correct 7 ms 11980 KB Output is correct
42 Correct 8 ms 12080 KB Output is correct
43 Correct 7 ms 12108 KB Output is correct
44 Correct 7 ms 11980 KB Output is correct
45 Correct 7 ms 12032 KB Output is correct
46 Correct 7 ms 12108 KB Output is correct
47 Correct 7 ms 11980 KB Output is correct
48 Correct 7 ms 12060 KB Output is correct
49 Correct 8 ms 12068 KB Output is correct
50 Correct 7 ms 12056 KB Output is correct
51 Correct 7 ms 12060 KB Output is correct
52 Correct 8 ms 11980 KB Output is correct
53 Correct 8 ms 12108 KB Output is correct
54 Correct 7 ms 11980 KB Output is correct
55 Correct 7 ms 11980 KB Output is correct
56 Correct 8 ms 11980 KB Output is correct
57 Correct 7 ms 11980 KB Output is correct
58 Correct 8 ms 12200 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 11980 KB Output is correct
2 Correct 8 ms 12060 KB Output is correct
3 Correct 7 ms 11980 KB Output is correct
4 Correct 7 ms 11980 KB Output is correct
5 Correct 7 ms 11980 KB Output is correct
6 Correct 7 ms 11980 KB Output is correct
7 Correct 7 ms 12060 KB Output is correct
8 Correct 7 ms 12060 KB Output is correct
9 Correct 8 ms 11980 KB Output is correct
10 Correct 8 ms 11980 KB Output is correct
11 Correct 8 ms 12060 KB Output is correct
12 Correct 7 ms 12004 KB Output is correct
13 Correct 7 ms 11980 KB Output is correct
14 Correct 7 ms 11980 KB Output is correct
15 Correct 7 ms 12060 KB Output is correct
16 Correct 7 ms 11980 KB Output is correct
17 Correct 7 ms 11980 KB Output is correct
18 Correct 7 ms 12060 KB Output is correct
19 Correct 7 ms 12060 KB Output is correct
20 Correct 7 ms 11980 KB Output is correct
21 Correct 7 ms 11980 KB Output is correct
22 Correct 8 ms 12108 KB Output is correct
23 Correct 7 ms 12108 KB Output is correct
24 Correct 8 ms 12196 KB Output is correct
25 Correct 8 ms 12108 KB Output is correct
26 Correct 8 ms 12108 KB Output is correct
27 Correct 8 ms 12184 KB Output is correct
28 Correct 8 ms 12072 KB Output is correct
29 Correct 8 ms 12108 KB Output is correct
30 Correct 9 ms 11980 KB Output is correct
31 Correct 8 ms 12108 KB Output is correct
32 Correct 8 ms 11980 KB Output is correct
33 Correct 7 ms 12060 KB Output is correct
34 Correct 7 ms 11980 KB Output is correct
35 Correct 7 ms 12064 KB Output is correct
36 Correct 7 ms 12060 KB Output is correct
37 Correct 7 ms 12028 KB Output is correct
38 Correct 7 ms 12108 KB Output is correct
39 Correct 7 ms 12060 KB Output is correct
40 Correct 8 ms 11980 KB Output is correct
41 Correct 7 ms 11980 KB Output is correct
42 Correct 8 ms 12080 KB Output is correct
43 Correct 7 ms 12108 KB Output is correct
44 Correct 7 ms 11980 KB Output is correct
45 Correct 7 ms 12032 KB Output is correct
46 Correct 7 ms 12108 KB Output is correct
47 Correct 7 ms 11980 KB Output is correct
48 Correct 7 ms 12060 KB Output is correct
49 Correct 8 ms 12068 KB Output is correct
50 Correct 7 ms 12056 KB Output is correct
51 Correct 7 ms 12060 KB Output is correct
52 Correct 8 ms 11980 KB Output is correct
53 Correct 8 ms 12108 KB Output is correct
54 Correct 7 ms 11980 KB Output is correct
55 Correct 7 ms 11980 KB Output is correct
56 Correct 8 ms 11980 KB Output is correct
57 Correct 7 ms 11980 KB Output is correct
58 Correct 8 ms 12200 KB Output is correct
59 Correct 339 ms 40616 KB Output is correct
60 Correct 417 ms 43376 KB Output is correct
61 Correct 7 ms 11980 KB Output is correct
62 Correct 7 ms 11992 KB Output is correct
63 Correct 300 ms 36616 KB Output is correct
64 Correct 9 ms 12492 KB Output is correct
65 Correct 18 ms 14176 KB Output is correct
66 Correct 136 ms 30532 KB Output is correct
67 Correct 451 ms 51084 KB Output is correct
68 Correct 452 ms 52880 KB Output is correct
69 Correct 13 ms 13004 KB Output is correct
70 Correct 83 ms 23268 KB Output is correct
71 Correct 294 ms 45792 KB Output is correct
72 Correct 313 ms 44320 KB Output is correct
73 Correct 85 ms 20016 KB Output is correct
74 Correct 418 ms 41136 KB Output is correct
75 Correct 32 ms 15796 KB Output is correct
76 Correct 302 ms 45364 KB Output is correct
77 Correct 296 ms 45448 KB Output is correct
78 Correct 32 ms 15808 KB Output is correct
79 Correct 448 ms 48748 KB Output is correct
80 Correct 9 ms 12236 KB Output is correct
81 Correct 102 ms 22468 KB Output is correct
82 Correct 369 ms 43248 KB Output is correct
83 Correct 432 ms 41132 KB Output is correct
84 Correct 429 ms 41264 KB Output is correct
85 Correct 439 ms 41088 KB Output is correct
86 Correct 433 ms 43308 KB Output is correct
87 Correct 428 ms 43316 KB Output is correct