#include"bits/stdc++.h"
#define int long long
// #define endl '\n'
using namespace std;
int dsu[2000001];
int ans[2000001];
int Find (int x) {
return dsu[x] == x ? x : dsu[x] = Find(dsu[x]);
}
void Union (int a, int b) {
dsu[Find(a)] = Find(b);
}
bool Query (int a, int b) {
cout << "2 " << a << " " << b << endl;
int x;
cin >> x;
return x == 1;
}
signed main () {
int n;
cin >> n;
set<pair<int,int>> s;
vector<int> num;
for (int i = 1 ; i <= n ; i++) s.insert({-1, i}), dsu[i] = i;
while (s.size() > 1) {
auto [X, Y] = *s.begin();
s.erase(s.begin());
bool found = 0;
for (auto [A, B] : s) {
if (Query(Y, B)) {
found = 1;
Union(B, Y);
s.erase({A, B});
s.insert({A + X, Find(B)});
break;
}
}
if (!found) {
num.push_back(Y);
}
}
auto [X, Y] = *s.begin();
num.push_back(Y);
int c = 1;
for (int i = 1 ; i <= n ; i++) if (dsu[i] == i) ans[i] = c++;
cout << 0 << " ";
for (int i = 1 ; i <= n ; i++) cout << ans[Find(i)] << " ";
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Partially correct |
38 ms |
200 KB |
Partially correct |
2 |
Partially correct |
40 ms |
200 KB |
Partially correct |
3 |
Partially correct |
63 ms |
200 KB |
Partially correct |
4 |
Partially correct |
67 ms |
200 KB |
Partially correct |
5 |
Correct |
15 ms |
200 KB |
Output is correct |
6 |
Correct |
3 ms |
200 KB |
Output is correct |
7 |
Partially correct |
46 ms |
200 KB |
Partially correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Partially correct |
40 ms |
200 KB |
Partially correct |
2 |
Partially correct |
55 ms |
200 KB |
Partially correct |
3 |
Partially correct |
50 ms |
252 KB |
Partially correct |
4 |
Partially correct |
79 ms |
200 KB |
Partially correct |
5 |
Correct |
31 ms |
200 KB |
Output is correct |
6 |
Correct |
10 ms |
200 KB |
Output is correct |
7 |
Partially correct |
46 ms |
200 KB |
Partially correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
200 KB |
Output is correct |
2 |
Partially correct |
42 ms |
200 KB |
Partially correct |
3 |
Partially correct |
57 ms |
292 KB |
Partially correct |
4 |
Partially correct |
106 ms |
292 KB |
Partially correct |
5 |
Correct |
26 ms |
328 KB |
Output is correct |
6 |
Correct |
25 ms |
304 KB |
Output is correct |
7 |
Partially correct |
54 ms |
200 KB |
Partially correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Partially correct |
35 ms |
200 KB |
Partially correct |
2 |
Partially correct |
40 ms |
200 KB |
Partially correct |
3 |
Partially correct |
78 ms |
296 KB |
Partially correct |
4 |
Partially correct |
102 ms |
300 KB |
Partially correct |
5 |
Partially correct |
51 ms |
200 KB |
Partially correct |
6 |
Partially correct |
43 ms |
200 KB |
Partially correct |
7 |
Partially correct |
63 ms |
296 KB |
Partially correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
30 ms |
200 KB |
Output is correct |
2 |
Partially correct |
41 ms |
200 KB |
Partially correct |
3 |
Partially correct |
66 ms |
296 KB |
Partially correct |
4 |
Partially correct |
60 ms |
304 KB |
Partially correct |
5 |
Partially correct |
56 ms |
320 KB |
Partially correct |
6 |
Partially correct |
69 ms |
300 KB |
Partially correct |
7 |
Partially correct |
86 ms |
296 KB |
Partially correct |