#include "icc.h"
#include <bits/stdc++.h>
using namespace std;
int *c, *d;
void dfs(
vector<vector<unsigned>> const &g, unsigned u, vector<unsigned> &y,
vector<bool> &vis)
{
y.push_back(u);
vis[u] = 1;
for (unsigned v : g[u])
if (!vis[v])
dfs(g, v, y, vis);
}
void fill_order(vector<vector<unsigned>> const &g, vector<vector<unsigned>> &y)
{
vector<bool> vis(g.size(), 0);
y.clear();
for (unsigned i = 0; i < g.size(); i++)
{
if (!vis[i])
{
y.push_back({});
dfs(g, i, y.back(), vis);
}
}
}
size_t add_components(int *z, vector<vector<unsigned>> const &y, size_t a, size_t b)
{
size_t size = 0;
for (size_t i = a; i < b; i++)
{
for (unsigned u : y[i])
{
z[size] = u + 1;
size++;
}
}
return size;
}
void run(int n)
{
c = (int *)malloc(n * sizeof(int));
d = (int *)malloc(n * sizeof(int));
vector<vector<unsigned>> g(n);
vector<vector<unsigned>> y;
for (unsigned z = 0; z < n - 1; z++)
{
fill_order(g, y);
size_t cs, ds;
while (1)
{
random_shuffle(y.begin(), y.end());
cs = add_components(c, y, 0, y.size() / 2);
ds = add_components(d, y, y.size() / 2, y.size());
if (query(cs, ds, c, d))
break;
}
size_t a = 0, b = cs - 1;
while (a < b)
{
size_t mid = (a + b) / 2;
if (query(mid + 1, ds, c, d))
b = mid;
else
a = mid + 1;
}
unsigned const u = c[a];
a = 0, b = ds - 1;
while (a < b)
{
size_t mid = (a + b) / 2;
if (query(cs, mid + 1, c, d))
b = mid;
else
a = mid + 1;
}
unsigned const v = d[a];
setRoad(u, v);
g[u - 1].push_back(v - 1);
g[v - 1].push_back(u - 1);
}
free(c);
free(d);
}
Compilation message
icc.cpp: In function 'void run(int)':
icc.cpp:55:28: warning: comparison of integer expressions of different signedness: 'unsigned int' and 'int' [-Wsign-compare]
55 | for (unsigned z = 0; z < n - 1; z++)
| ~~^~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
468 KB |
Ok! 103 queries used. |
2 |
Correct |
6 ms |
424 KB |
Ok! 94 queries used. |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
28 ms |
496 KB |
Ok! 550 queries used. |
2 |
Correct |
47 ms |
484 KB |
Ok! 837 queries used. |
3 |
Correct |
44 ms |
484 KB |
Ok! 843 queries used. |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
108 ms |
484 KB |
Ok! 1480 queries used. |
2 |
Correct |
163 ms |
488 KB |
Ok! 2108 queries used. |
3 |
Correct |
126 ms |
484 KB |
Ok! 1705 queries used. |
4 |
Correct |
123 ms |
488 KB |
Ok! 1700 queries used. |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
115 ms |
480 KB |
Ok! 1619 queries used. |
2 |
Correct |
110 ms |
484 KB |
Ok! 1507 queries used. |
3 |
Correct |
134 ms |
468 KB |
Ok! 1867 queries used. |
4 |
Correct |
117 ms |
468 KB |
Ok! 1587 queries used. |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
138 ms |
468 KB |
Too many queries! 1900 out of 1775 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
137 ms |
484 KB |
Too many queries! 1906 out of 1625 |
2 |
Halted |
0 ms |
0 KB |
- |