#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());
if (X > 1e9) continue;
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;
}else {
s.insert({X * 2, Y});
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)] << " ";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
31 ms |
352 KB |
Integer 12 violates the range [1, 11] |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
27 ms |
328 KB |
Integer 6 violates the range [1, 5] |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
200 KB |
Output is correct |
2 |
Incorrect |
48 ms |
332 KB |
Integer 9 violates the range [1, 8] |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
14 ms |
324 KB |
Integer 105 violates the range [1, 4] |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
23 ms |
320 KB |
Integer 70 violates the range [1, 2] |
2 |
Halted |
0 ms |
0 KB |
- |