//CEOI '16 P1
//Problem: ICC
//Link: https://oj.uz/problem/view/CEOI16_icc
#include <bits/stdc++.h>
#include "icc.h"
using namespace std;
#define lg long long
const lg MOD = 1e9+7, N = 101, M = 1e7+1, SZ = 1e3+1;
lg par[N], compSize[N];
vector<lg> child[N];
lg getParent(lg src)
{
if(src == par[src]) return src;
return par[src] = getParent(par[src]);
}
void join(lg u, lg v)
{
u = getParent(u), v = getParent(v);
if(u == v) return;
if(compSize[u] > compSize[v]) swap(u, v);
par[u] = v;
for(auto it : child[u]) child[v].push_back(it);
compSize[v] += compSize[u];
}
void run(int n)
{
for(int i = 1; i <= n; i++) par[i] = i, compSize[i] = 1, child[i].push_back(i);
lg x = n-1;
while(x--)
{
vector<lg> parents;
for(int i = 1; i <= n; i++) if(par[i] == i) parents.push_back(i);
bool cur = true;
lg sz = parents.size();
for(int i = 0; i < sz && cur; i++)
{
for(int j = i+1; j < sz && cur; j++)
{
lg u = parents[i], v = parents[j];
if(getParent(u) == getParent(v)) continue;
lg sz1 = child[u].size(), sz2 = child[v].size();
int a[sz1], b[sz2];
for(int k = 0; k < sz1; k++) a[k] = child[u][k];
for(int k = 0; k < sz2; k++) b[k] = child[v][k];
bool flag = query(sz1, sz2, a, b);
if(flag)
{
if(sz1 == 1 && sz2 == 1)
{
join(a[0], b[0]);
setRoad(a[0], b[0]);
cur = false;
break;
}
for(int k = 0; k < sz1; k++)
{
int z[] = {a[k]};
bool cur = query(1, sz2, z, b);
if(cur)
{
for(int g = 0; g < sz2; g++)
{
int y[] = {b[g]};
bool cur2 = query(1, 1, z, y);
if(cur2)
{
join(z[0], y[0]);
setRoad(z[0], y[0]);
}
else{
continue;
}
}
}
}
cur = false;
break;
}
}
}
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
28 ms |
468 KB |
Ok! 677 queries used. |
2 |
Correct |
30 ms |
468 KB |
Ok! 674 queries used. |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
262 ms |
468 KB |
Number of queries more than 5000 out of 2500 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
334 ms |
484 KB |
Number of queries more than 4500 out of 2250 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
325 ms |
488 KB |
Number of queries more than 4000 out of 2000 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
302 ms |
484 KB |
Number of queries more than 3550 out of 1775 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
269 ms |
484 KB |
Number of queries more than 3250 out of 1625 |
2 |
Halted |
0 ms |
0 KB |
- |