#include <bits/stdc++.h>
using namespace std;
// #define endl '\n'
const int M = 2e5+5, MOD = 1000000007;
#define int long long
int rnk[M], clr[M], p[M];
vector<pair<int, int>> nono;
int find(int s) {
return (s == p[s]?s:p[s]=find(p[s]));
}
void uni(int a, int b) {
if (rnk[a] < rnk[b]) swap(a, b);
if (rnk[a] == rnk[b]) rnk[a]++;
p[b] = a;
}
signed main() {
cin.tie(0)->sync_with_stdio(0);
int n;
cin >> n;
for (int i = 1; i <= n; i++) clr[i] = p[i] = i;
for (int i=1;i<=n;i++) {
for(int j=i+1;j<=n;j++) {
bool check = 1;
for (auto [a, b]:nono) {
int x, y;
x = find(a), y = find(b);
int w = find(i), z = find(j);
if (x > y) swap(x, y);
if (w > z) swap(w, z);
if (w==x && z == y) check = 0;
}
if (find(i) != find(j) && check) {
cout << 2 << ' ' << i << ' ' << j << endl;
int x;
cin >> x;
if (x == 1) uni(find(i), find(j));
else {
nono.push_back({find(i), find(j)});
}
}
}
}
map<int, int> mp;
set<int> st;
for (int i = 1; i <= n; i++) st.insert(find(i));
int cnt = 1;
for (int i:st) mp[i] = cnt++;
cout << 0 << ' ';
for (int i = 1; i <= n; i++) cout << mp[clr[find(i)]] << ' '; cout << endl;
return 0;
}
/*
3
0 3 0
3 0 0
5 4 0
3
1 1 1
3 0 1
4 5 1
*/
Compilation message
carnival.cpp: In function 'int main()':
carnival.cpp:31:23: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
31 | for (auto [a, b]:nono) {
| ^
carnival.cpp:61:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
61 | for (int i = 1; i <= n; i++) cout << mp[clr[find(i)]] << ' '; cout << endl;
| ^~~
carnival.cpp:61:67: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
61 | for (int i = 1; i <= n; i++) cout << mp[clr[find(i)]] << ' '; cout << endl;
| ^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
42 ms |
464 KB |
Output is correct |
2 |
Correct |
126 ms |
424 KB |
Output is correct |
3 |
Partially correct |
246 ms |
620 KB |
Partially correct |
4 |
Partially correct |
257 ms |
928 KB |
Partially correct |
5 |
Correct |
8 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
104 ms |
360 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
17 ms |
352 KB |
Output is correct |
2 |
Correct |
128 ms |
368 KB |
Output is correct |
3 |
Partially correct |
124 ms |
520 KB |
Partially correct |
4 |
Partially correct |
300 ms |
600 KB |
Partially correct |
5 |
Correct |
10 ms |
344 KB |
Output is correct |
6 |
Correct |
6 ms |
336 KB |
Output is correct |
7 |
Correct |
45 ms |
336 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
208 KB |
Output is correct |
2 |
Correct |
36 ms |
336 KB |
Output is correct |
3 |
Partially correct |
235 ms |
516 KB |
Partially correct |
4 |
Partially correct |
344 ms |
748 KB |
Partially correct |
5 |
Correct |
24 ms |
336 KB |
Output is correct |
6 |
Correct |
29 ms |
356 KB |
Output is correct |
7 |
Correct |
206 ms |
552 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
336 KB |
Output is correct |
2 |
Correct |
31 ms |
348 KB |
Output is correct |
3 |
Partially correct |
364 ms |
704 KB |
Partially correct |
4 |
Partially correct |
405 ms |
976 KB |
Partially correct |
5 |
Correct |
49 ms |
352 KB |
Output is correct |
6 |
Correct |
132 ms |
428 KB |
Output is correct |
7 |
Correct |
162 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
336 KB |
Output is correct |
2 |
Correct |
95 ms |
364 KB |
Output is correct |
3 |
Partially correct |
331 ms |
540 KB |
Partially correct |
4 |
Partially correct |
381 ms |
552 KB |
Partially correct |
5 |
Correct |
179 ms |
432 KB |
Output is correct |
6 |
Partially correct |
275 ms |
636 KB |
Partially correct |
7 |
Partially correct |
508 ms |
600 KB |
Partially correct |