답안 #829318

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
829318 2023-08-18T09:05:43 Z MohamedAhmed04 Meetings (JOI19_meetings) C++14
100 / 100
664 ms 860 KB
#include <bits/stdc++.h>
#include "meetings.h"

using namespace std ;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()) ;

int rand(int l , int r)
{
	return uniform_int_distribution<int>(l , r)(rng) ;
}

const int MAX = 2004 ;

int n ;

vector< pair<int , int> >ans ;

vector<int>subtree[MAX] ;

int curroot ;

bool cmp(int &a , int &b)
{
	return (Query(curroot , a , b) == a) ;
}

void solve(int root , vector<int>v)
{
	if(!v.size())
		return ;
	curroot = root ;
	shuffle(v.begin() , v.end() , rng) ;
	subtree[root].clear() ;
	for(auto &node : v)
		subtree[node].clear() ;
	int x = v.back() ;
	v.pop_back() ;
	vector<int>path = {x} ;
	for(auto &node : v)
	{
		int lca = Query(root , x , node) ;
		if(lca != node)
			subtree[lca].push_back(node) ;
		if(lca != root)
			path.push_back(lca) ;
	}
	sort(path.begin() , path.end()) ;
	path.erase(unique(path.begin() , path.end()) , path.end()) ;
	sort(path.begin() , path.end() , cmp) ;
	ans.emplace_back(root , path[0]) ;
	for(int i = 0 ; i+1 < path.size() ; ++i)
		ans.emplace_back(path[i] , path[i+1]) ;
	solve(root , subtree[root]) ;
	for(auto &node : path)
		solve(node , subtree[node]) ;
}

void Solve(int N) 
{
	n = N ;
	int root = rand(0 , n-1) ;
	vector<int>v ;
	for(int i = 0 ; i < n ; ++i)
	{
		if(i != root)
			v.push_back(i) ;
	}
	solve(root , v) ;
	for(auto &p : ans)
		Bridge(min(p.first , p.second) , max(p.first , p.second)) ;
}

Compilation message

meetings.cpp: In function 'void solve(int, std::vector<int>)':
meetings.cpp:52:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   52 |  for(int i = 0 ; i+1 < path.size() ; ++i)
      |                  ~~~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 336 KB Output is correct
2 Correct 0 ms 336 KB Output is correct
3 Correct 0 ms 336 KB Output is correct
4 Correct 0 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 0 ms 336 KB Output is correct
7 Correct 0 ms 336 KB Output is correct
8 Correct 0 ms 336 KB Output is correct
9 Correct 0 ms 336 KB Output is correct
10 Correct 0 ms 336 KB Output is correct
11 Correct 0 ms 336 KB Output is correct
12 Correct 0 ms 336 KB Output is correct
13 Correct 0 ms 336 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 336 KB Output is correct
2 Correct 0 ms 336 KB Output is correct
3 Correct 0 ms 336 KB Output is correct
4 Correct 0 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 0 ms 336 KB Output is correct
7 Correct 0 ms 336 KB Output is correct
8 Correct 0 ms 336 KB Output is correct
9 Correct 0 ms 336 KB Output is correct
10 Correct 0 ms 336 KB Output is correct
11 Correct 0 ms 336 KB Output is correct
12 Correct 0 ms 336 KB Output is correct
13 Correct 0 ms 336 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 0 ms 336 KB Output is correct
16 Correct 0 ms 400 KB Output is correct
17 Correct 0 ms 336 KB Output is correct
18 Correct 0 ms 336 KB Output is correct
19 Correct 1 ms 336 KB Output is correct
20 Correct 0 ms 336 KB Output is correct
21 Correct 0 ms 336 KB Output is correct
22 Correct 0 ms 336 KB Output is correct
23 Correct 0 ms 336 KB Output is correct
24 Correct 1 ms 336 KB Output is correct
25 Correct 0 ms 336 KB Output is correct
26 Correct 1 ms 336 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 336 KB Output is correct
2 Correct 0 ms 336 KB Output is correct
3 Correct 0 ms 336 KB Output is correct
4 Correct 0 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 0 ms 336 KB Output is correct
7 Correct 0 ms 336 KB Output is correct
8 Correct 0 ms 336 KB Output is correct
9 Correct 0 ms 336 KB Output is correct
10 Correct 0 ms 336 KB Output is correct
11 Correct 0 ms 336 KB Output is correct
12 Correct 0 ms 336 KB Output is correct
13 Correct 0 ms 336 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 0 ms 336 KB Output is correct
16 Correct 0 ms 400 KB Output is correct
17 Correct 0 ms 336 KB Output is correct
18 Correct 0 ms 336 KB Output is correct
19 Correct 1 ms 336 KB Output is correct
20 Correct 0 ms 336 KB Output is correct
21 Correct 0 ms 336 KB Output is correct
22 Correct 0 ms 336 KB Output is correct
23 Correct 0 ms 336 KB Output is correct
24 Correct 1 ms 336 KB Output is correct
25 Correct 0 ms 336 KB Output is correct
26 Correct 1 ms 336 KB Output is correct
27 Correct 4 ms 336 KB Output is correct
28 Correct 3 ms 336 KB Output is correct
29 Correct 4 ms 336 KB Output is correct
30 Correct 4 ms 336 KB Output is correct
31 Correct 4 ms 336 KB Output is correct
32 Correct 5 ms 336 KB Output is correct
33 Correct 8 ms 336 KB Output is correct
34 Correct 9 ms 336 KB Output is correct
35 Correct 9 ms 336 KB Output is correct
36 Correct 4 ms 336 KB Output is correct
37 Correct 9 ms 464 KB Output is correct
38 Correct 9 ms 464 KB Output is correct
39 Correct 4 ms 464 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 232 ms 660 KB Output is correct
2 Correct 225 ms 640 KB Output is correct
3 Correct 287 ms 640 KB Output is correct
4 Correct 231 ms 724 KB Output is correct
5 Correct 195 ms 696 KB Output is correct
6 Correct 213 ms 848 KB Output is correct
7 Correct 381 ms 592 KB Output is correct
8 Correct 479 ms 772 KB Output is correct
9 Correct 452 ms 716 KB Output is correct
10 Correct 420 ms 860 KB Output is correct
11 Correct 487 ms 676 KB Output is correct
12 Correct 199 ms 684 KB Output is correct
13 Correct 147 ms 732 KB Output is correct
14 Correct 342 ms 712 KB Output is correct
15 Correct 253 ms 616 KB Output is correct
16 Correct 301 ms 608 KB Output is correct
17 Correct 488 ms 620 KB Output is correct
18 Correct 244 ms 592 KB Output is correct
19 Correct 256 ms 732 KB Output is correct
20 Correct 275 ms 600 KB Output is correct
21 Correct 258 ms 632 KB Output is correct
22 Correct 290 ms 624 KB Output is correct
23 Correct 248 ms 644 KB Output is correct
24 Correct 231 ms 604 KB Output is correct
25 Correct 230 ms 644 KB Output is correct
26 Correct 235 ms 628 KB Output is correct
27 Correct 269 ms 616 KB Output is correct
28 Correct 544 ms 600 KB Output is correct
29 Correct 384 ms 660 KB Output is correct
30 Correct 429 ms 668 KB Output is correct
31 Correct 478 ms 768 KB Output is correct
32 Correct 664 ms 740 KB Output is correct
33 Correct 465 ms 692 KB Output is correct
34 Correct 4 ms 336 KB Output is correct
35 Correct 4 ms 336 KB Output is correct
36 Correct 4 ms 336 KB Output is correct
37 Correct 3 ms 336 KB Output is correct
38 Correct 4 ms 336 KB Output is correct
39 Correct 8 ms 440 KB Output is correct
40 Correct 7 ms 336 KB Output is correct
41 Correct 9 ms 456 KB Output is correct
42 Correct 9 ms 336 KB Output is correct
43 Correct 3 ms 336 KB Output is correct
44 Correct 9 ms 436 KB Output is correct
45 Correct 8 ms 440 KB Output is correct
46 Correct 7 ms 464 KB Output is correct
47 Correct 0 ms 336 KB Output is correct
48 Correct 1 ms 336 KB Output is correct
49 Correct 0 ms 336 KB Output is correct
50 Correct 0 ms 336 KB Output is correct
51 Correct 0 ms 336 KB Output is correct
52 Correct 0 ms 336 KB Output is correct
53 Correct 0 ms 336 KB Output is correct
54 Correct 1 ms 336 KB Output is correct
55 Correct 0 ms 336 KB Output is correct
56 Correct 0 ms 336 KB Output is correct
57 Correct 1 ms 336 KB Output is correct
58 Correct 0 ms 336 KB Output is correct
59 Correct 0 ms 336 KB Output is correct
60 Correct 0 ms 336 KB Output is correct
61 Correct 1 ms 336 KB Output is correct
62 Correct 0 ms 336 KB Output is correct
63 Correct 0 ms 336 KB Output is correct
64 Correct 0 ms 336 KB Output is correct
65 Correct 1 ms 336 KB Output is correct
66 Correct 0 ms 336 KB Output is correct
67 Correct 0 ms 336 KB Output is correct
68 Correct 0 ms 336 KB Output is correct
69 Correct 0 ms 336 KB Output is correct
70 Correct 0 ms 336 KB Output is correct
71 Correct 0 ms 336 KB Output is correct
72 Correct 0 ms 336 KB Output is correct