#include "meetings.h"
#include<bits/stdc++.h>
using ll = long long;
using namespace std;
#define pll pair <ll,ll>
#define fi first
#define se second
#define MP make_pair
#define sz(a) (ll((a).size()))
#define BIT(mask,i) (((mask) >> (i))&1)
#define MASK(i) (1LL << (i))
const ll MAXN = 2010;
mt19937_64 rng(69420);
ll random(ll l,ll r){
return rng()%(r-l+1)+l;
}
vector <ll> sub[MAXN];
ll lose[MAXN];
void dfs(ll u){
sort(sub[u].begin(),sub[u].end(),[](ll x,ll y){return lose[x]<lose[y];});
for (auto v:sub[u]){
if (lose[v] == lose[sub[u][0]]){
// cout<<"BR "<<u<<' '<<v<<endl;
Bridge(min(u,v),max(u,v));
dfs(v);
}
else break;
}
}
void solve(vector <ll> all){
if (sz(all)<2)return;
sort(all.begin(),all.end());
ll x = all[random(0,sz(all)-1)];
ll y = x;
while (y==x)y=all[random(0,sz(all)-1)];
map <ll,vector <ll> > mp;
for (auto z:all){
if (z!=x&&z!=y){
ll tmp = Query(x,y,z);
mp[tmp].push_back(z);
}
}
vector <ll> path;
path.push_back(x);
path.push_back(y);
for (auto z:mp)if (z.fi != x && z.fi != y){
path.push_back(z.fi);
}
stable_sort(path.begin(),path.end(),[&](ll a1,ll a2)->bool{
if (a1==x)return 1;
if (a2==x)return 0;
return Query(x,a1,a2)==a1;
});
for (ll j = 0;j + 1 < sz(path);j ++){
// cout<<path[j]<<' '<<path[j+1]<<'\n';
Bridge(min(path[j],path[j+1]),max(path[j],path[j+1]));
}
for (auto z:mp){
vector <ll> tmp = z.se;
tmp.push_back(z.fi);
sort(tmp.begin(),tmp.end());
tmp.resize(unique(tmp.begin(),tmp.end())-tmp.begin());
solve(tmp);
}
}
void Solve(int n) {
vector <ll> all(n);
iota(all.begin(),all.end(),0);
solve(all);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
344 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 |
344 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 |
1 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
344 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 |
344 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 |
1 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 |
1 ms |
344 KB |
Output is correct |
18 |
Correct |
0 ms |
344 KB |
Output is correct |
19 |
Correct |
1 ms |
344 KB |
Output is correct |
20 |
Correct |
0 ms |
344 KB |
Output is correct |
21 |
Correct |
0 ms |
344 KB |
Output is correct |
22 |
Correct |
1 ms |
344 KB |
Output is correct |
23 |
Correct |
0 ms |
344 KB |
Output is correct |
24 |
Correct |
0 ms |
344 KB |
Output is correct |
25 |
Correct |
0 ms |
376 KB |
Output is correct |
26 |
Correct |
0 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
344 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 |
344 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 |
1 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 |
1 ms |
344 KB |
Output is correct |
18 |
Correct |
0 ms |
344 KB |
Output is correct |
19 |
Correct |
1 ms |
344 KB |
Output is correct |
20 |
Correct |
0 ms |
344 KB |
Output is correct |
21 |
Correct |
0 ms |
344 KB |
Output is correct |
22 |
Correct |
1 ms |
344 KB |
Output is correct |
23 |
Correct |
0 ms |
344 KB |
Output is correct |
24 |
Correct |
0 ms |
344 KB |
Output is correct |
25 |
Correct |
0 ms |
376 KB |
Output is correct |
26 |
Correct |
0 ms |
344 KB |
Output is correct |
27 |
Correct |
3 ms |
596 KB |
Output is correct |
28 |
Correct |
2 ms |
576 KB |
Output is correct |
29 |
Correct |
3 ms |
344 KB |
Output is correct |
30 |
Correct |
2 ms |
600 KB |
Output is correct |
31 |
Correct |
2 ms |
344 KB |
Output is correct |
32 |
Correct |
2 ms |
600 KB |
Output is correct |
33 |
Correct |
3 ms |
600 KB |
Output is correct |
34 |
Correct |
4 ms |
596 KB |
Output is correct |
35 |
Correct |
4 ms |
600 KB |
Output is correct |
36 |
Correct |
2 ms |
344 KB |
Output is correct |
37 |
Correct |
5 ms |
600 KB |
Output is correct |
38 |
Correct |
6 ms |
600 KB |
Output is correct |
39 |
Correct |
3 ms |
624 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
156 ms |
848 KB |
Output is correct |
2 |
Correct |
155 ms |
852 KB |
Output is correct |
3 |
Correct |
158 ms |
848 KB |
Output is correct |
4 |
Correct |
170 ms |
1004 KB |
Output is correct |
5 |
Correct |
127 ms |
600 KB |
Output is correct |
6 |
Correct |
119 ms |
848 KB |
Output is correct |
7 |
Correct |
199 ms |
848 KB |
Output is correct |
8 |
Correct |
261 ms |
848 KB |
Output is correct |
9 |
Correct |
269 ms |
848 KB |
Output is correct |
10 |
Correct |
246 ms |
1104 KB |
Output is correct |
11 |
Correct |
268 ms |
1052 KB |
Output is correct |
12 |
Correct |
109 ms |
848 KB |
Output is correct |
13 |
Correct |
86 ms |
1148 KB |
Output is correct |
14 |
Correct |
143 ms |
848 KB |
Output is correct |
15 |
Correct |
150 ms |
912 KB |
Output is correct |
16 |
Correct |
123 ms |
788 KB |
Output is correct |
17 |
Correct |
221 ms |
852 KB |
Output is correct |
18 |
Correct |
125 ms |
876 KB |
Output is correct |
19 |
Correct |
119 ms |
756 KB |
Output is correct |
20 |
Correct |
121 ms |
848 KB |
Output is correct |
21 |
Correct |
156 ms |
1008 KB |
Output is correct |
22 |
Correct |
145 ms |
848 KB |
Output is correct |
23 |
Correct |
144 ms |
840 KB |
Output is correct |
24 |
Correct |
142 ms |
772 KB |
Output is correct |
25 |
Correct |
114 ms |
848 KB |
Output is correct |
26 |
Correct |
112 ms |
856 KB |
Output is correct |
27 |
Correct |
114 ms |
816 KB |
Output is correct |
28 |
Correct |
296 ms |
804 KB |
Output is correct |
29 |
Correct |
180 ms |
944 KB |
Output is correct |
30 |
Correct |
206 ms |
848 KB |
Output is correct |
31 |
Correct |
216 ms |
848 KB |
Output is correct |
32 |
Correct |
390 ms |
1104 KB |
Output is correct |
33 |
Correct |
171 ms |
964 KB |
Output is correct |
34 |
Correct |
3 ms |
600 KB |
Output is correct |
35 |
Correct |
3 ms |
600 KB |
Output is correct |
36 |
Correct |
2 ms |
344 KB |
Output is correct |
37 |
Correct |
2 ms |
600 KB |
Output is correct |
38 |
Correct |
2 ms |
344 KB |
Output is correct |
39 |
Correct |
2 ms |
600 KB |
Output is correct |
40 |
Correct |
3 ms |
600 KB |
Output is correct |
41 |
Correct |
4 ms |
600 KB |
Output is correct |
42 |
Correct |
4 ms |
612 KB |
Output is correct |
43 |
Correct |
2 ms |
564 KB |
Output is correct |
44 |
Correct |
6 ms |
608 KB |
Output is correct |
45 |
Correct |
6 ms |
596 KB |
Output is correct |
46 |
Correct |
3 ms |
608 KB |
Output is correct |
47 |
Correct |
0 ms |
344 KB |
Output is correct |
48 |
Correct |
0 ms |
344 KB |
Output is correct |
49 |
Correct |
0 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 |
0 ms |
344 KB |
Output is correct |
54 |
Correct |
0 ms |
344 KB |
Output is correct |
55 |
Correct |
0 ms |
344 KB |
Output is correct |
56 |
Correct |
0 ms |
344 KB |
Output is correct |
57 |
Correct |
0 ms |
344 KB |
Output is correct |
58 |
Correct |
0 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 |
344 KB |
Output is correct |
63 |
Correct |
0 ms |
344 KB |
Output is correct |
64 |
Correct |
0 ms |
344 KB |
Output is correct |
65 |
Correct |
0 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 |
384 KB |
Output is correct |
69 |
Correct |
0 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 |