#include "meetings.h"
#include<bits/stdc++.h>
using namespace std;
#define fast ios::sync_with_stdio(false); cin.tie(0);
#define fi first
#define se second
#define pb push_back
#define em emplace
#define eb emplace_back
#define mp make_pair
#define all(v) (v).begin(), (v).end()
#define pre(x) cout<<fixed; cout.precision(x);
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int inf = 1e9;
const ll INF = 1e18;
int n;
vector<int> g[2010];
int sz[2010];
bool chk[2010];
bool in[2010];
int cnt;
const int MX = 100000;
int q(int u, int v, int w) {
cnt++;
assert(0 <= u && u < n);
assert(0 <= v && v < n);
assert(0 <= w && w < n);
assert(u != v && v != w && w != u);
assert(cnt <= 100000);
return Query(u, v, w);
}
void dfs(int x, int p = 0) {
sz[x] = 1;
for(auto i : g[x]) {
if(i == p || chk[i]) continue;
dfs(i, x);
sz[x] += sz[i];
}
}
int Cen(int x) {
int s = 1, mx = 0, mxi;
for(auto i : g[x]) {
if(chk[i]) continue;
s += sz[i];
if(sz[i] > mx) mx = sz[i], mxi = i;
}
if(mx > s/2) {
sz[x] = s - mx;
return Cen(mxi);
}
return x;
}
pii Find(int x) {
memset(chk, 0, sizeof(chk));
int r = 0;
while(1) {
dfs(r);
r = Cen(r);
//cout << r << "!!!" << endl;
sort(all(g[r]), [](int i, int j) {
return sz[i] > sz[j];
});
for(int i=0; i<g[r].size(); i+=2) {
if(i+1 == g[r].size()) {
if(q(g[r][i], r, x) != r) {
if(chk[g[r][i]]) return mp(r, g[r][i]);
chk[r] = true;
r = g[r][i];
break;
}
}
else if(q(g[r][i], g[r][i+1], x) != r) {
chk[r] = true;
int nr;
if(q(g[r][i], r, x) != r) nr = g[r][i];
else nr = g[r][i+1];
if(chk[nr]) return mp(r, nr);
r = nr;
break;
}
if(i+2 >= g[r].size()) return mp(r, r);
}
}
}
void Solve(int N) {
n = N;
cnt = 0;
for(int i=0; i<n; i++) g[i].clear(), chk[i] = in[i] = false;
g[0].eb(1);
g[1].eb(0);
for(int i=2; i<n; i++) {
if(in[i]) continue;
int u, v;
tie(u, v) = Find(i);
//cout << i << ": " << u << " " << v << "\n";
if(u == v) {
g[u].eb(i);
g[i].eb(u);
continue;
}
int tmp = q(u, v, i);
//cout << tmp << "!\n";
if(tmp == u) {
g[u].eb(i);
g[i].eb(u);
}
else if(tmp == v) {
g[v].eb(i);
g[i].eb(v);
}
else {
if(tmp != i) {
g[tmp].eb(i);
g[i].eb(tmp);
}
g[tmp].eb(u);
g[tmp].eb(v);
for(auto &j : g[u]) if(j == v) j = tmp;
for(auto &j : g[v]) if(j == u) j = tmp;
in[tmp] = true;
}
}
int e = 0;
for(int i=0; i<n; i++) {
for(auto j : g[i]) {
if(i < j) {
e++;
Bridge(i, j);
}
}
}
assert(e == n-1);
}
Compilation message
meetings.cpp: In function 'pii Find(int)':
meetings.cpp:74:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
74 | for(int i=0; i<g[r].size(); i+=2) {
| ~^~~~~~~~~~~~
meetings.cpp:75:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
75 | if(i+1 == g[r].size()) {
| ~~~~^~~~~~~~~~~~~~
meetings.cpp:92:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
92 | if(i+2 >= g[r].size()) return mp(r, r);
| ~~~~^~~~~~~~~~~~~~
meetings.cpp: In function 'int Cen(int)':
meetings.cpp:51:22: warning: 'mxi' may be used uninitialized in this function [-Wmaybe-uninitialized]
51 | int s = 1, mx = 0, mxi;
| ^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
544 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
596 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
10 |
Correct |
0 ms |
344 KB |
Output is correct |
11 |
Correct |
0 ms |
344 KB |
Output is correct |
12 |
Correct |
0 ms |
344 KB |
Output is correct |
13 |
Correct |
0 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
544 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
596 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
10 |
Correct |
0 ms |
344 KB |
Output is correct |
11 |
Correct |
0 ms |
344 KB |
Output is correct |
12 |
Correct |
0 ms |
344 KB |
Output is correct |
13 |
Correct |
0 ms |
344 KB |
Output is correct |
14 |
Correct |
1 ms |
344 KB |
Output is correct |
15 |
Correct |
1 ms |
344 KB |
Output is correct |
16 |
Correct |
0 ms |
344 KB |
Output is correct |
17 |
Correct |
0 ms |
344 KB |
Output is correct |
18 |
Correct |
1 ms |
344 KB |
Output is correct |
19 |
Correct |
0 ms |
344 KB |
Output is correct |
20 |
Correct |
1 ms |
344 KB |
Output is correct |
21 |
Correct |
1 ms |
344 KB |
Output is correct |
22 |
Correct |
0 ms |
344 KB |
Output is correct |
23 |
Correct |
0 ms |
344 KB |
Output is correct |
24 |
Correct |
1 ms |
344 KB |
Output is correct |
25 |
Correct |
1 ms |
344 KB |
Output is correct |
26 |
Correct |
1 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
544 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
596 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
10 |
Correct |
0 ms |
344 KB |
Output is correct |
11 |
Correct |
0 ms |
344 KB |
Output is correct |
12 |
Correct |
0 ms |
344 KB |
Output is correct |
13 |
Correct |
0 ms |
344 KB |
Output is correct |
14 |
Correct |
1 ms |
344 KB |
Output is correct |
15 |
Correct |
1 ms |
344 KB |
Output is correct |
16 |
Correct |
0 ms |
344 KB |
Output is correct |
17 |
Correct |
0 ms |
344 KB |
Output is correct |
18 |
Correct |
1 ms |
344 KB |
Output is correct |
19 |
Correct |
0 ms |
344 KB |
Output is correct |
20 |
Correct |
1 ms |
344 KB |
Output is correct |
21 |
Correct |
1 ms |
344 KB |
Output is correct |
22 |
Correct |
0 ms |
344 KB |
Output is correct |
23 |
Correct |
0 ms |
344 KB |
Output is correct |
24 |
Correct |
1 ms |
344 KB |
Output is correct |
25 |
Correct |
1 ms |
344 KB |
Output is correct |
26 |
Correct |
1 ms |
344 KB |
Output is correct |
27 |
Correct |
5 ms |
344 KB |
Output is correct |
28 |
Correct |
6 ms |
564 KB |
Output is correct |
29 |
Correct |
5 ms |
344 KB |
Output is correct |
30 |
Correct |
5 ms |
344 KB |
Output is correct |
31 |
Correct |
5 ms |
344 KB |
Output is correct |
32 |
Correct |
4 ms |
344 KB |
Output is correct |
33 |
Correct |
6 ms |
344 KB |
Output is correct |
34 |
Correct |
9 ms |
344 KB |
Output is correct |
35 |
Correct |
6 ms |
344 KB |
Output is correct |
36 |
Correct |
6 ms |
344 KB |
Output is correct |
37 |
Correct |
11 ms |
600 KB |
Output is correct |
38 |
Correct |
11 ms |
600 KB |
Output is correct |
39 |
Correct |
9 ms |
600 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
353 ms |
736 KB |
Output is correct |
2 |
Correct |
356 ms |
600 KB |
Output is correct |
3 |
Correct |
377 ms |
952 KB |
Output is correct |
4 |
Correct |
330 ms |
744 KB |
Output is correct |
5 |
Correct |
346 ms |
740 KB |
Output is correct |
6 |
Correct |
325 ms |
848 KB |
Output is correct |
7 |
Correct |
328 ms |
764 KB |
Output is correct |
8 |
Correct |
376 ms |
600 KB |
Output is correct |
9 |
Correct |
339 ms |
776 KB |
Output is correct |
10 |
Correct |
315 ms |
968 KB |
Output is correct |
11 |
Correct |
381 ms |
712 KB |
Output is correct |
12 |
Correct |
514 ms |
792 KB |
Output is correct |
13 |
Correct |
381 ms |
980 KB |
Output is correct |
14 |
Correct |
381 ms |
980 KB |
Output is correct |
15 |
Correct |
357 ms |
716 KB |
Output is correct |
16 |
Correct |
391 ms |
764 KB |
Output is correct |
17 |
Correct |
333 ms |
700 KB |
Output is correct |
18 |
Correct |
359 ms |
1020 KB |
Output is correct |
19 |
Correct |
366 ms |
764 KB |
Output is correct |
20 |
Correct |
382 ms |
712 KB |
Output is correct |
21 |
Correct |
377 ms |
1224 KB |
Output is correct |
22 |
Correct |
377 ms |
968 KB |
Output is correct |
23 |
Correct |
404 ms |
736 KB |
Output is correct |
24 |
Correct |
368 ms |
704 KB |
Output is correct |
25 |
Correct |
363 ms |
964 KB |
Output is correct |
26 |
Correct |
359 ms |
760 KB |
Output is correct |
27 |
Correct |
365 ms |
956 KB |
Output is correct |
28 |
Correct |
392 ms |
772 KB |
Output is correct |
29 |
Correct |
330 ms |
964 KB |
Output is correct |
30 |
Correct |
315 ms |
780 KB |
Output is correct |
31 |
Correct |
332 ms |
764 KB |
Output is correct |
32 |
Correct |
841 ms |
860 KB |
Output is correct |
33 |
Correct |
609 ms |
884 KB |
Output is correct |
34 |
Correct |
5 ms |
344 KB |
Output is correct |
35 |
Correct |
6 ms |
344 KB |
Output is correct |
36 |
Correct |
5 ms |
344 KB |
Output is correct |
37 |
Correct |
5 ms |
344 KB |
Output is correct |
38 |
Correct |
5 ms |
344 KB |
Output is correct |
39 |
Correct |
4 ms |
596 KB |
Output is correct |
40 |
Correct |
5 ms |
344 KB |
Output is correct |
41 |
Correct |
6 ms |
344 KB |
Output is correct |
42 |
Correct |
6 ms |
344 KB |
Output is correct |
43 |
Correct |
7 ms |
344 KB |
Output is correct |
44 |
Correct |
10 ms |
600 KB |
Output is correct |
45 |
Correct |
11 ms |
600 KB |
Output is correct |
46 |
Correct |
9 ms |
600 KB |
Output is correct |
47 |
Correct |
1 ms |
344 KB |
Output is correct |
48 |
Correct |
0 ms |
344 KB |
Output is correct |
49 |
Correct |
1 ms |
344 KB |
Output is correct |
50 |
Correct |
1 ms |
344 KB |
Output is correct |
51 |
Correct |
1 ms |
344 KB |
Output is correct |
52 |
Correct |
0 ms |
344 KB |
Output is correct |
53 |
Correct |
1 ms |
344 KB |
Output is correct |
54 |
Correct |
1 ms |
344 KB |
Output is correct |
55 |
Correct |
0 ms |
340 KB |
Output is correct |
56 |
Correct |
1 ms |
596 KB |
Output is correct |
57 |
Correct |
1 ms |
344 KB |
Output is correct |
58 |
Correct |
1 ms |
344 KB |
Output is correct |
59 |
Correct |
0 ms |
344 KB |
Output is correct |
60 |
Correct |
0 ms |
344 KB |
Output is correct |
61 |
Correct |
0 ms |
344 KB |
Output is correct |
62 |
Correct |
0 ms |
596 KB |
Output is correct |
63 |
Correct |
0 ms |
344 KB |
Output is correct |
64 |
Correct |
0 ms |
344 KB |
Output is correct |
65 |
Correct |
1 ms |
344 KB |
Output is correct |
66 |
Correct |
0 ms |
344 KB |
Output is correct |
67 |
Correct |
0 ms |
344 KB |
Output is correct |
68 |
Correct |
0 ms |
344 KB |
Output is correct |
69 |
Correct |
1 ms |
344 KB |
Output is correct |
70 |
Correct |
0 ms |
344 KB |
Output is correct |
71 |
Correct |
0 ms |
344 KB |
Output is correct |
72 |
Correct |
0 ms |
344 KB |
Output is correct |