답안 #394608

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
394608 2021-04-27T05:47:57 Z RohamIzadidoost Network (BOI15_net) C++14
100 / 100
792 ms 45136 KB
#pragma GCC optimize("Ofast,unroll-loops,fast-math")
#include<bits/stdc++.h>
using namespace std;
typedef long long ll ;
#define pll pair<ll , ll >
#define all(x) (x).begin(),(x).end()
#define SZ(x) (ll)(x).size()
#define X   first
#define Y   second
#define mp  make_pair
#define pii pair<int , int>
#define vec vector
#define file_io freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
#define migmig ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb push_back
#define ld long double
// BIG p : 1000000000000037 , 100000000003
ll poww(ll a, ll b, ll md) {
    return (!b ? 1 : (b & 1 ? a * poww(a * a % md, b / 2, md) % md : poww(a * a % md, b / 2, md) % md));
}
const int maxn = 5000*100+5 ;
const ll inf = 9223372036854775807 ;
const ll mod = 1e9 + 7 ;
const int lg = 20 ;
int n , nl , st[maxn]  , cnt , mark[maxn];
vec<pii> l ; 
vec<int> adj[maxn] ; 
void dfs(int v ){
	st[v] = cnt ++; 
	mark[v] = 1 ; 
	for(auto u : adj[v]) if(!mark[u]) dfs(u) ;
}
int main()
{
	migmig ;
	cin>>n ; 
	for(int i = 1 ; i < n ; i ++ ){
		int u , v ; 
		cin>>u>>v ; 
		adj[u].pb(v) ;
		adj[v].pb(u) ; 
	}
	for(int i = 1 ; i <= n ; i ++ ){
		if(adj[i].size() != 1){
			dfs(i) ; 
			break ; 
		}
	}
	vec<pii> v ; 
	for(int i = 1 ; i <= n ; i ++ ){
		if(SZ(adj[i]) == 1){
			nl ++ ; 
			v.pb({st[i] , i}) ; 
		}
	}
	sort(all(v)) ; 
	cout<<(nl + 1 ) / 2 <<endl ; 
	nl = (nl + 1) / 2 ; 
	for(int i = 0 ; i + nl < SZ(v) ; i ++ ){
		cout<<v[i].Y <<" " << v[i + nl].Y << endl ; 
	}
	if(SZ(v) % 2 == 1){
		cout<<v[nl-1].Y <<" " << v[0].Y << endl ; 
	}
}








# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 11980 KB Output is correct
2 Correct 9 ms 11980 KB Output is correct
3 Correct 9 ms 11980 KB Output is correct
4 Correct 9 ms 11984 KB Output is correct
5 Correct 10 ms 11980 KB Output is correct
6 Correct 9 ms 11980 KB Output is correct
7 Correct 9 ms 12040 KB Output is correct
8 Correct 10 ms 12056 KB Output is correct
9 Correct 10 ms 12032 KB Output is correct
10 Correct 9 ms 11980 KB Output is correct
11 Correct 9 ms 11980 KB Output is correct
12 Correct 9 ms 11984 KB Output is correct
13 Correct 9 ms 11980 KB Output is correct
14 Correct 8 ms 11980 KB Output is correct
15 Correct 8 ms 11980 KB Output is correct
16 Correct 10 ms 12000 KB Output is correct
17 Correct 8 ms 11980 KB Output is correct
18 Correct 10 ms 11980 KB Output is correct
19 Correct 9 ms 11980 KB Output is correct
20 Correct 11 ms 11980 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 11980 KB Output is correct
2 Correct 9 ms 11980 KB Output is correct
3 Correct 9 ms 11980 KB Output is correct
4 Correct 9 ms 11984 KB Output is correct
5 Correct 10 ms 11980 KB Output is correct
6 Correct 9 ms 11980 KB Output is correct
7 Correct 9 ms 12040 KB Output is correct
8 Correct 10 ms 12056 KB Output is correct
9 Correct 10 ms 12032 KB Output is correct
10 Correct 9 ms 11980 KB Output is correct
11 Correct 9 ms 11980 KB Output is correct
12 Correct 9 ms 11984 KB Output is correct
13 Correct 9 ms 11980 KB Output is correct
14 Correct 8 ms 11980 KB Output is correct
15 Correct 8 ms 11980 KB Output is correct
16 Correct 10 ms 12000 KB Output is correct
17 Correct 8 ms 11980 KB Output is correct
18 Correct 10 ms 11980 KB Output is correct
19 Correct 9 ms 11980 KB Output is correct
20 Correct 11 ms 11980 KB Output is correct
21 Correct 8 ms 12064 KB Output is correct
22 Correct 13 ms 12108 KB Output is correct
23 Correct 11 ms 12108 KB Output is correct
24 Correct 10 ms 12108 KB Output is correct
25 Correct 22 ms 12108 KB Output is correct
26 Correct 10 ms 12128 KB Output is correct
27 Correct 11 ms 12124 KB Output is correct
28 Correct 11 ms 12068 KB Output is correct
29 Correct 10 ms 12108 KB Output is correct
30 Correct 8 ms 11980 KB Output is correct
31 Correct 10 ms 12108 KB Output is correct
32 Correct 9 ms 12000 KB Output is correct
33 Correct 9 ms 11980 KB Output is correct
34 Correct 8 ms 11980 KB Output is correct
35 Correct 10 ms 11980 KB Output is correct
36 Correct 8 ms 12000 KB Output is correct
37 Correct 9 ms 12120 KB Output is correct
38 Correct 9 ms 12108 KB Output is correct
39 Correct 10 ms 11980 KB Output is correct
40 Correct 10 ms 11980 KB Output is correct
41 Correct 8 ms 11980 KB Output is correct
42 Correct 9 ms 12108 KB Output is correct
43 Correct 9 ms 12108 KB Output is correct
44 Correct 8 ms 12020 KB Output is correct
45 Correct 9 ms 12080 KB Output is correct
46 Correct 9 ms 12108 KB Output is correct
47 Correct 8 ms 12064 KB Output is correct
48 Correct 9 ms 11980 KB Output is correct
49 Correct 9 ms 12108 KB Output is correct
50 Correct 9 ms 11980 KB Output is correct
51 Correct 10 ms 12064 KB Output is correct
52 Correct 9 ms 11980 KB Output is correct
53 Correct 9 ms 12036 KB Output is correct
54 Correct 8 ms 11980 KB Output is correct
55 Correct 9 ms 11980 KB Output is correct
56 Correct 9 ms 11980 KB Output is correct
57 Correct 9 ms 11980 KB Output is correct
58 Correct 11 ms 12108 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 11980 KB Output is correct
2 Correct 9 ms 11980 KB Output is correct
3 Correct 9 ms 11980 KB Output is correct
4 Correct 9 ms 11984 KB Output is correct
5 Correct 10 ms 11980 KB Output is correct
6 Correct 9 ms 11980 KB Output is correct
7 Correct 9 ms 12040 KB Output is correct
8 Correct 10 ms 12056 KB Output is correct
9 Correct 10 ms 12032 KB Output is correct
10 Correct 9 ms 11980 KB Output is correct
11 Correct 9 ms 11980 KB Output is correct
12 Correct 9 ms 11984 KB Output is correct
13 Correct 9 ms 11980 KB Output is correct
14 Correct 8 ms 11980 KB Output is correct
15 Correct 8 ms 11980 KB Output is correct
16 Correct 10 ms 12000 KB Output is correct
17 Correct 8 ms 11980 KB Output is correct
18 Correct 10 ms 11980 KB Output is correct
19 Correct 9 ms 11980 KB Output is correct
20 Correct 11 ms 11980 KB Output is correct
21 Correct 8 ms 12064 KB Output is correct
22 Correct 13 ms 12108 KB Output is correct
23 Correct 11 ms 12108 KB Output is correct
24 Correct 10 ms 12108 KB Output is correct
25 Correct 22 ms 12108 KB Output is correct
26 Correct 10 ms 12128 KB Output is correct
27 Correct 11 ms 12124 KB Output is correct
28 Correct 11 ms 12068 KB Output is correct
29 Correct 10 ms 12108 KB Output is correct
30 Correct 8 ms 11980 KB Output is correct
31 Correct 10 ms 12108 KB Output is correct
32 Correct 9 ms 12000 KB Output is correct
33 Correct 9 ms 11980 KB Output is correct
34 Correct 8 ms 11980 KB Output is correct
35 Correct 10 ms 11980 KB Output is correct
36 Correct 8 ms 12000 KB Output is correct
37 Correct 9 ms 12120 KB Output is correct
38 Correct 9 ms 12108 KB Output is correct
39 Correct 10 ms 11980 KB Output is correct
40 Correct 10 ms 11980 KB Output is correct
41 Correct 8 ms 11980 KB Output is correct
42 Correct 9 ms 12108 KB Output is correct
43 Correct 9 ms 12108 KB Output is correct
44 Correct 8 ms 12020 KB Output is correct
45 Correct 9 ms 12080 KB Output is correct
46 Correct 9 ms 12108 KB Output is correct
47 Correct 8 ms 12064 KB Output is correct
48 Correct 9 ms 11980 KB Output is correct
49 Correct 9 ms 12108 KB Output is correct
50 Correct 9 ms 11980 KB Output is correct
51 Correct 10 ms 12064 KB Output is correct
52 Correct 9 ms 11980 KB Output is correct
53 Correct 9 ms 12036 KB Output is correct
54 Correct 8 ms 11980 KB Output is correct
55 Correct 9 ms 11980 KB Output is correct
56 Correct 9 ms 11980 KB Output is correct
57 Correct 9 ms 11980 KB Output is correct
58 Correct 11 ms 12108 KB Output is correct
59 Correct 677 ms 34680 KB Output is correct
60 Correct 776 ms 37312 KB Output is correct
61 Correct 8 ms 11980 KB Output is correct
62 Correct 8 ms 11980 KB Output is correct
63 Correct 669 ms 32608 KB Output is correct
64 Correct 10 ms 12492 KB Output is correct
65 Correct 20 ms 13804 KB Output is correct
66 Correct 169 ms 27072 KB Output is correct
67 Correct 568 ms 44228 KB Output is correct
68 Correct 575 ms 45136 KB Output is correct
69 Correct 31 ms 12952 KB Output is correct
70 Correct 237 ms 20984 KB Output is correct
71 Correct 792 ms 41024 KB Output is correct
72 Correct 732 ms 40112 KB Output is correct
73 Correct 162 ms 18868 KB Output is correct
74 Correct 681 ms 35868 KB Output is correct
75 Correct 75 ms 15168 KB Output is correct
76 Correct 742 ms 40604 KB Output is correct
77 Correct 756 ms 40948 KB Output is correct
78 Correct 45 ms 15428 KB Output is correct
79 Correct 523 ms 42432 KB Output is correct
80 Correct 12 ms 12236 KB Output is correct
81 Correct 215 ms 21040 KB Output is correct
82 Correct 729 ms 38448 KB Output is correct
83 Correct 676 ms 36028 KB Output is correct
84 Correct 696 ms 35888 KB Output is correct
85 Correct 684 ms 35956 KB Output is correct
86 Correct 751 ms 37316 KB Output is correct
87 Correct 765 ms 37512 KB Output is correct