#include "meetings.h"
#include <bits/stdc++.h>
using namespace std;
void bridge( int u, int v ) {
if ( u > v )
swap( u, v );
Bridge( u, v );
}
void solve( int root, vector<int> &subtree ) {
if ( subtree.size() == 0 )
return;
//random_shuffle( subtree.begin(), subtree.end() );
unordered_map<int, vector<int>> newSubtrees;
vector<int> path;
int pivot = subtree[0];
for ( int i = 1; i < subtree.size(); i++ ) {
int ans = Query( root, pivot, subtree[i] );
if ( ans == subtree[i] )
path.push_back( subtree[i] );
else
newSubtrees[ans].push_back( subtree[i] );
}
for ( int i = 1; i < path.size(); i++ ) {
int l = -1, r = i;
while ( r - l > 1 ) {
int mid = (l + r) / 2;
if ( Query( root, path[mid], path[i] ) == path[mid] )
l = mid;
else
r = mid;
}
for ( int j = i; j > r; j-- )
swap( path[j], path[j - 1] );
}
if ( path.size() == 0 )
bridge( root, pivot );
else {
bridge( root, path[0] );
for ( int i = 0; i < path.size() - 1; i++ )
bridge( path[i], path[i + 1] );
bridge( path[path.size() - 1], pivot );
}
for ( auto &st: newSubtrees )
solve( st.first, st.second );
}
void Solve( int n ) {
int root = 0;
vector<int> subtree;
for ( int u = 1; u < n; u++ )
subtree.push_back( u );
solve( root, subtree );
}
Compilation message
meetings.cpp: In function 'void solve(int, std::vector<int>&)':
meetings.cpp:21:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
21 | for ( int i = 1; i < subtree.size(); i++ ) {
| ~~^~~~~~~~~~~~~~~~
meetings.cpp:29:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
29 | for ( int i = 1; i < path.size(); i++ ) {
| ~~^~~~~~~~~~~~~
meetings.cpp:47:28: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
47 | for ( int i = 0; i < path.size() - 1; i++ )
| ~~^~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 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 |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
0 ms |
336 KB |
Output is correct |
13 |
Correct |
1 ms |
336 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 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 |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
0 ms |
336 KB |
Output is correct |
13 |
Correct |
1 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 |
0 ms |
336 KB |
Output is correct |
18 |
Correct |
1 ms |
336 KB |
Output is correct |
19 |
Correct |
1 ms |
344 KB |
Output is correct |
20 |
Correct |
1 ms |
336 KB |
Output is correct |
21 |
Correct |
1 ms |
336 KB |
Output is correct |
22 |
Correct |
1 ms |
336 KB |
Output is correct |
23 |
Correct |
1 ms |
336 KB |
Output is correct |
24 |
Correct |
1 ms |
340 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 |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 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 |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
0 ms |
336 KB |
Output is correct |
13 |
Correct |
1 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 |
0 ms |
336 KB |
Output is correct |
18 |
Correct |
1 ms |
336 KB |
Output is correct |
19 |
Correct |
1 ms |
344 KB |
Output is correct |
20 |
Correct |
1 ms |
336 KB |
Output is correct |
21 |
Correct |
1 ms |
336 KB |
Output is correct |
22 |
Correct |
1 ms |
336 KB |
Output is correct |
23 |
Correct |
1 ms |
336 KB |
Output is correct |
24 |
Correct |
1 ms |
340 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 |
380 KB |
Output is correct |
28 |
Correct |
3 ms |
336 KB |
Output is correct |
29 |
Correct |
4 ms |
392 KB |
Output is correct |
30 |
Correct |
3 ms |
368 KB |
Output is correct |
31 |
Correct |
3 ms |
336 KB |
Output is correct |
32 |
Correct |
5 ms |
472 KB |
Output is correct |
33 |
Correct |
10 ms |
340 KB |
Output is correct |
34 |
Correct |
14 ms |
388 KB |
Output is correct |
35 |
Correct |
15 ms |
412 KB |
Output is correct |
36 |
Correct |
3 ms |
336 KB |
Output is correct |
37 |
Correct |
4 ms |
336 KB |
Output is correct |
38 |
Correct |
8 ms |
336 KB |
Output is correct |
39 |
Correct |
109 ms |
672 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
201 ms |
560 KB |
Output is correct |
2 |
Correct |
226 ms |
588 KB |
Output is correct |
3 |
Correct |
275 ms |
588 KB |
Output is correct |
4 |
Correct |
410 ms |
592 KB |
Output is correct |
5 |
Correct |
177 ms |
572 KB |
Output is correct |
6 |
Correct |
203 ms |
636 KB |
Output is correct |
7 |
Correct |
381 ms |
612 KB |
Output is correct |
8 |
Correct |
451 ms |
704 KB |
Output is correct |
9 |
Correct |
494 ms |
616 KB |
Output is correct |
10 |
Correct |
409 ms |
732 KB |
Output is correct |
11 |
Correct |
510 ms |
688 KB |
Output is correct |
12 |
Correct |
233 ms |
700 KB |
Output is correct |
13 |
Correct |
109 ms |
608 KB |
Output is correct |
14 |
Correct |
336 ms |
664 KB |
Output is correct |
15 |
Correct |
311 ms |
592 KB |
Output is correct |
16 |
Correct |
286 ms |
740 KB |
Output is correct |
17 |
Correct |
617 ms |
632 KB |
Output is correct |
18 |
Incorrect |
1537 ms |
940 KB |
Wrong Answer [2] |
19 |
Halted |
0 ms |
0 KB |
- |