#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 ;
int mark[MAX] ;
void solve(int root , vector<int>v)
{
if(!v.size())
return ;
shuffle(v.begin() , v.end() , rng) ;
for(auto &node : v)
mark[node] = 0 ;
vector< vector<int> >subtrees = {{v.back()}} ;
v.pop_back() ;
for(auto &node : v)
{
if(mark[node])
continue ;
mark[node] = 1 ;
bool flag = false ;
for(auto &v2 : subtrees)
{
int lca = Query(root , node , v2.back()) ;
if(lca == root)
continue ;
flag = true , mark[lca] = 1 ;
v2.push_back(node) ;
int sz = v2.size() ;
if(lca != v2[sz-1])
swap(v2[sz-1] , v2[sz-2]) ;
if(lca != v2[sz-1])
v2.push_back(lca) ;
break ;
}
if(!flag)
subtrees.push_back({node}) ;
}
for(auto &v2 : subtrees)
{
int root2 = v2.back() ;
ans.emplace_back(min(root , root2) , max(root , root2)) ;
v2.pop_back() ;
solve(root2 , v2) ;
}
}
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(p.first , p.second) ;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 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 |
0 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 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 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 |
0 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 |
0 ms |
336 KB |
Output is correct |
15 |
Correct |
0 ms |
336 KB |
Output is correct |
16 |
Correct |
0 ms |
336 KB |
Output is correct |
17 |
Correct |
1 ms |
336 KB |
Output is correct |
18 |
Correct |
1 ms |
336 KB |
Output is correct |
19 |
Correct |
1 ms |
336 KB |
Output is correct |
20 |
Correct |
1 ms |
336 KB |
Output is correct |
21 |
Correct |
1 ms |
336 KB |
Output is correct |
22 |
Correct |
0 ms |
336 KB |
Output is correct |
23 |
Correct |
1 ms |
336 KB |
Output is correct |
24 |
Correct |
1 ms |
336 KB |
Output is correct |
25 |
Correct |
1 ms |
336 KB |
Output is correct |
26 |
Correct |
1 ms |
336 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 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 |
0 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 |
0 ms |
336 KB |
Output is correct |
15 |
Correct |
0 ms |
336 KB |
Output is correct |
16 |
Correct |
0 ms |
336 KB |
Output is correct |
17 |
Correct |
1 ms |
336 KB |
Output is correct |
18 |
Correct |
1 ms |
336 KB |
Output is correct |
19 |
Correct |
1 ms |
336 KB |
Output is correct |
20 |
Correct |
1 ms |
336 KB |
Output is correct |
21 |
Correct |
1 ms |
336 KB |
Output is correct |
22 |
Correct |
0 ms |
336 KB |
Output is correct |
23 |
Correct |
1 ms |
336 KB |
Output is correct |
24 |
Correct |
1 ms |
336 KB |
Output is correct |
25 |
Correct |
1 ms |
336 KB |
Output is correct |
26 |
Correct |
1 ms |
336 KB |
Output is correct |
27 |
Correct |
8 ms |
336 KB |
Output is correct |
28 |
Correct |
10 ms |
404 KB |
Output is correct |
29 |
Correct |
6 ms |
336 KB |
Output is correct |
30 |
Correct |
9 ms |
376 KB |
Output is correct |
31 |
Correct |
6 ms |
336 KB |
Output is correct |
32 |
Correct |
5 ms |
336 KB |
Output is correct |
33 |
Correct |
12 ms |
400 KB |
Output is correct |
34 |
Correct |
11 ms |
336 KB |
Output is correct |
35 |
Correct |
9 ms |
388 KB |
Output is correct |
36 |
Correct |
8 ms |
336 KB |
Output is correct |
37 |
Correct |
84 ms |
668 KB |
Output is correct |
38 |
Correct |
82 ms |
616 KB |
Output is correct |
39 |
Correct |
100 ms |
712 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
481 ms |
748 KB |
Output is correct |
2 |
Correct |
475 ms |
668 KB |
Output is correct |
3 |
Correct |
531 ms |
764 KB |
Output is correct |
4 |
Correct |
417 ms |
644 KB |
Output is correct |
5 |
Correct |
837 ms |
784 KB |
Output is correct |
6 |
Correct |
340 ms |
628 KB |
Output is correct |
7 |
Correct |
449 ms |
620 KB |
Output is correct |
8 |
Correct |
615 ms |
600 KB |
Output is correct |
9 |
Correct |
506 ms |
608 KB |
Output is correct |
10 |
Correct |
471 ms |
752 KB |
Output is correct |
11 |
Correct |
563 ms |
608 KB |
Output is correct |
12 |
Incorrect |
1802 ms |
1396 KB |
Wrong Answer [2] |
13 |
Halted |
0 ms |
0 KB |
- |