//Problem Name: Carnival
//Problem Link: https://oj.uz/problem/view/CEOI14_carnival
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("Ofast")
using namespace std;
using namespace __gnu_pbds;
#define lg long long
#define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args);
#define lbound(x, y) lower_bound(x.begin(), x.end(), y)
#define ubound(x, y) upper_bound(x.begin(), x.end(), y)
#define sortasc(v) sort(v.begin(), v.end())
#define sortdesc(v) sort(v.rbegin(), v.rend())
#define custom_array(a,l, r) int _##a[r-l+1]; int*a=_##a-l;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const lg MOD = 1e9+7, N = 2e5+5, M = 1e7+1, SZ = 1e3+1;
/*
bitset<N> primes;
lg pwrs[N], inv[N];
lg fast_power(lg n, lg k)
{
if(!k) return 1;
if(k&1) return (fast_power(n, k-1)*n)%MOD;
lg x = fast_power(n, k/2)%MOD;
return (x*x)%MOD;
}
void sieve()
{
primes.set();
primes[0] = primes[1] = 0;
for(lg i = 2; i < N; i++)
{
if(!primes[i]) continue;
for(lg j = i*i; j < N; j += i)
{
primes[j] = 0;
}
}
return;
}
struct matrix
{
vector<vector<lg>> con = vector<vector<lg>> (SZ, vector<lg> (SZ));
matrix operator *(const matrix& a)
{
matrix product;
for(int i = 0; i < (lg)con.size(); i++)
{
for(int j = 0; j < (lg)a.con[0].size(); j++)
{
for(int k = 0; k < (lg)a.con.size(); k++)
{
product.con[i][j] = (product.con[i][j]+(con[i][k]*a.con[k][j])%MOD)%MOD;
}
}
}
return product;
}
};
void preprocess(lg x)
{
inv[2e5] = fast_power(x, MOD-2);
for(int i = 2e5-1; i > 1; i--)
{
inv[i] = (inv[i+1]*i)%MOD;
}
pwrs[0] = 1;
for(int i = 1; i <= 2e5; i++)
{
pwrs[i] = (pwrs[i]*i)%MOD;
}
return;
}
*/
lg par1[N], compSize1[N], par2[N], compSize2[N];
lg getParent1(lg src)
{
if(src == par1[src]) return src;
return par1[src] = getParent1(par1[src]);
}
void join1(lg u, lg v)
{
u = getParent1(u), v = getParent1(v);
if(u == v) return;
if(compSize1[u] > compSize1[v]) swap(u, v);
compSize1[v] += compSize1[u];
par1[u] = v;
return;
}
lg getParent2(lg src)
{
if(src == par2[src]) return src;
return par2[src] = getParent1(par2[src]);
}
void join2(lg u, lg v)
{
u = getParent2(u), v = getParent2(v);
if(u == v) return;
compSize2[v] += compSize2[u];
par2[u] = v;
return;
}
int main()
{
fastio;
lg n;
cin >> n;
for(int i = 1; i <= n; i++) par1[i] = i, compSize1[i] = 1, par2[i] = i, compSize2[i] = 1;
for(int i = 1; i <= n; i++)
{
for(int j = i+1; j <= n; j++)
{
if(getParent1(i) == getParent1(j)) continue;
if(getParent2(i) == getParent2(j)) continue;
cout << "2 " << i << ' ' << j << endl;
lg x;
cin >> x;
if(x == 1) join1(i, j);
else join2(i, j);
}
}
cout << "0 ";
map<lg, lg> mp;
lg id = 1;
for(int i = 1; i <= n; i++)
{
getParent1(i);
if(!mp[par1[i]])
{
mp[par1[i]] = id++;
}
cout << mp[par1[i]] << ' ';
}
cout << endl;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Partially correct |
90 ms |
336 KB |
Partially correct |
2 |
Partially correct |
67 ms |
336 KB |
Partially correct |
3 |
Partially correct |
90 ms |
336 KB |
Partially correct |
4 |
Partially correct |
83 ms |
336 KB |
Partially correct |
5 |
Partially correct |
45 ms |
336 KB |
Partially correct |
6 |
Correct |
4 ms |
336 KB |
Output is correct |
7 |
Partially correct |
76 ms |
336 KB |
Partially correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Partially correct |
71 ms |
336 KB |
Partially correct |
2 |
Partially correct |
117 ms |
336 KB |
Partially correct |
3 |
Partially correct |
44 ms |
336 KB |
Partially correct |
4 |
Partially correct |
115 ms |
336 KB |
Partially correct |
5 |
Partially correct |
48 ms |
336 KB |
Partially correct |
6 |
Correct |
20 ms |
336 KB |
Output is correct |
7 |
Partially correct |
78 ms |
336 KB |
Partially correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
336 KB |
Output is correct |
2 |
Partially correct |
76 ms |
336 KB |
Partially correct |
3 |
Partially correct |
41 ms |
336 KB |
Partially correct |
4 |
Partially correct |
52 ms |
336 KB |
Partially correct |
5 |
Partially correct |
73 ms |
336 KB |
Partially correct |
6 |
Partially correct |
22 ms |
336 KB |
Partially correct |
7 |
Partially correct |
83 ms |
336 KB |
Partially correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Partially correct |
82 ms |
336 KB |
Partially correct |
2 |
Partially correct |
81 ms |
336 KB |
Partially correct |
3 |
Partially correct |
110 ms |
336 KB |
Partially correct |
4 |
Partially correct |
84 ms |
336 KB |
Partially correct |
5 |
Partially correct |
65 ms |
336 KB |
Partially correct |
6 |
Partially correct |
82 ms |
336 KB |
Partially correct |
7 |
Partially correct |
80 ms |
336 KB |
Partially correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Partially correct |
55 ms |
336 KB |
Partially correct |
2 |
Partially correct |
101 ms |
336 KB |
Partially correct |
3 |
Partially correct |
89 ms |
336 KB |
Partially correct |
4 |
Incorrect |
128 ms |
336 KB |
Integer 100 violates the range [1, 99] |
5 |
Halted |
0 ms |
0 KB |
- |