// partially_correct/partial-author.cpp
#include <bits/stdc++.h>
#include "sphinx.h"
using namespace std;
#ifdef DEBUG
#define D(x...) fprintf(stderr, x)
#define DA(x) assert(x)
#else
#define D(x...)
#define DA(x)
#endif
const int MAX_N = 250 + 10;
const int ACTUAL_COLOR = -1;
int n;
vector<int> adjlist[MAX_N];
vector<int> proposed_colors;
namespace components {
int TT;
int seen[MAX_N];
// Mark all as seen from u.
void dfs(int u) {
seen[u] = TT;
for (auto v : adjlist[u]) {
if (proposed_colors[u] != ACTUAL_COLOR &&
proposed_colors[u] == proposed_colors[v] && seen[v] != TT) {
dfs(v);
}
}
}
// Return number of components in a vector
int num_components(vector<int> &vertices) {
TT++;
int ret = 0;
for (auto u : vertices) {
if (seen[u] != TT) {
ret++;
dfs(u);
}
}
return ret;
}
} // namespace components
namespace forest {
int ugroup[MAX_N];
vector<int> members[MAX_N];
vector<int> get_groups(int limit) {
vector<int> res;
for (int i = 0; i < limit; i++) {
if (!members[i].empty()) {
res.push_back(i);
}
}
return res;
}
int get(int x) { return ugroup[x]; }
void join(int x, int y) {
int gx = get(x);
int gy = get(y);
if (members[gx].size() > members[gy].size()) {
swap(gx, gy);
}
for (auto u : members[gx]) {
ugroup[u] = gy;
members[gy].push_back(u);
}
members[gx].clear();
}
// query for number of components in groups [s, e] union {cur}
int queryOnly(vector<int> &groups, int s, int e, int cur) {
D("queryOnly\n");
fill(proposed_colors.begin(), proposed_colors.end(), n);
for (int i = s; i < e; i++) {
for (auto u : members[groups[i]]) {
D("%d ", u);
proposed_colors[u] = ACTUAL_COLOR;
}
}
proposed_colors[cur] = ACTUAL_COLOR;
D("%d\n", cur);
vector<int> others;
for (int i = 0; i < n; i++) {
if (proposed_colors[i] == n) {
others.push_back(i);
}
}
int others_components = components::num_components(others);
auto found = perform_experiment(proposed_colors);
auto res = found - others_components;
D("queryOnly %d: found %d, others components = %d\n", res, found,
others_components);
return res;
}
// how many edges are from cur to vertices in groups [s, e) ?
int extra_edges(vector<int> &groups, int s, int e, int cur) {
auto if_none = e - s + 1;
auto components = queryOnly(groups, s, e, cur);
auto edges = if_none - components;
D("extra_edges=%d for [%d, %d) with cur=%d: if_none=%d, components=%d\n",
edges, s, e, cur, if_none, components);
return edges;
}
// there are num_edges edges from cur to vertices in groups [s,e).
// find them and unionise with cur.
void solve(vector<int> &groups, int s, int e, int num_edges, int cur) {
D("solve([");
for (int i = s; i < e; i++) {
D("%d ", groups[i]);
}
D("], num_edges=%d, cur=%d)\n", num_edges, cur);
DA(num_edges <= e - s);
if (num_edges == 0) return;
if (e - s == num_edges) {
for (int i = s; i < e; i++) {
auto u = members[groups[i]].front();
D("! identified that %d and %d are in the same color component\n", cur,
u);
join(cur, u);
}
return;
}
DA(e - s > 1);
int mid = (e + s) / 2;
auto left_edges = extra_edges(groups, s, mid, cur);
DA(0 <= left_edges && left_edges <= num_edges);
solve(groups, s, mid, left_edges, cur);
solve(groups, mid, e, num_edges - left_edges, cur);
}
void go() {
for (int i = 0; i < n; i++) {
ugroup[i] = i;
members[i].push_back(i);
}
for (int i = 1; i < n; i++) {
auto groups = get_groups(i);
D("* i=%d\n", i);
auto edges = extra_edges(groups, 0, groups.size(), i);
solve(groups, 0, groups.size(), edges, i);
}
}
} // namespace forest
vector<int> find_colours(int _n, vector<int> a, vector<int> b) {
n = _n;
for (int i = 0; i < n; i++) {
proposed_colors.push_back(ACTUAL_COLOR);
}
int m = a.size();
for (int i = 0; i < m; i++) {
auto u = a[i];
auto v = b[i];
adjlist[u].push_back(v);
adjlist[v].push_back(u);
}
forest::go();
vector<int> ret;
for (int i = 0; i < n; i++) {
int g = forest::get(i);
ret.push_back(g);
}
return ret;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Partially correct |
0 ms |
344 KB |
Partially correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
#experiments: 1 |
2 |
Correct |
0 ms |
444 KB |
#experiments: 1 |
3 |
Partially correct |
1 ms |
344 KB |
Partially correct |
4 |
Partially correct |
0 ms |
344 KB |
Partially correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Partially correct |
0 ms |
344 KB |
Partially correct |
2 |
Correct |
0 ms |
344 KB |
#experiments: 1 |
3 |
Correct |
0 ms |
444 KB |
#experiments: 1 |
4 |
Partially correct |
1 ms |
344 KB |
Partially correct |
5 |
Partially correct |
0 ms |
344 KB |
Partially correct |
6 |
Partially correct |
1 ms |
344 KB |
Partially correct |
7 |
Partially correct |
1 ms |
344 KB |
Partially correct |
8 |
Partially correct |
2 ms |
344 KB |
Partially correct |
9 |
Partially correct |
1 ms |
344 KB |
Partially correct |
10 |
Partially correct |
2 ms |
344 KB |
Partially correct |
11 |
Partially correct |
2 ms |
344 KB |
Partially correct |
12 |
Partially correct |
1 ms |
344 KB |
Partially correct |
13 |
Partially correct |
1 ms |
344 KB |
Partially correct |
14 |
Partially correct |
1 ms |
344 KB |
Partially correct |
15 |
Partially correct |
2 ms |
344 KB |
Partially correct |
16 |
Partially correct |
4 ms |
344 KB |
Partially correct |
17 |
Partially correct |
3 ms |
344 KB |
Partially correct |
18 |
Partially correct |
5 ms |
344 KB |
Partially correct |
19 |
Partially correct |
3 ms |
344 KB |
Partially correct |
20 |
Partially correct |
2 ms |
344 KB |
Partially correct |
21 |
Partially correct |
1 ms |
344 KB |
Partially correct |
22 |
Partially correct |
1 ms |
344 KB |
Partially correct |
23 |
Partially correct |
1 ms |
344 KB |
Partially correct |
24 |
Partially correct |
1 ms |
344 KB |
Partially correct |
25 |
Partially correct |
2 ms |
344 KB |
Partially correct |
26 |
Partially correct |
2 ms |
344 KB |
Partially correct |
27 |
Partially correct |
1 ms |
344 KB |
Partially correct |
28 |
Partially correct |
1 ms |
344 KB |
Partially correct |
29 |
Partially correct |
2 ms |
344 KB |
Partially correct |
30 |
Partially correct |
2 ms |
344 KB |
Partially correct |
31 |
Partially correct |
2 ms |
344 KB |
Partially correct |
32 |
Partially correct |
3 ms |
344 KB |
Partially correct |
33 |
Partially correct |
1 ms |
344 KB |
Partially correct |
34 |
Partially correct |
1 ms |
344 KB |
Partially correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
#experiments: 1 |
2 |
Correct |
0 ms |
444 KB |
#experiments: 1 |
3 |
Partially correct |
1 ms |
344 KB |
Partially correct |
4 |
Partially correct |
0 ms |
344 KB |
Partially correct |
5 |
Partially correct |
1 ms |
344 KB |
Partially correct |
6 |
Partially correct |
1 ms |
344 KB |
Partially correct |
7 |
Partially correct |
2 ms |
344 KB |
Partially correct |
8 |
Partially correct |
1 ms |
344 KB |
Partially correct |
9 |
Partially correct |
2 ms |
344 KB |
Partially correct |
10 |
Partially correct |
2 ms |
344 KB |
Partially correct |
11 |
Partially correct |
1 ms |
344 KB |
Partially correct |
12 |
Partially correct |
1 ms |
344 KB |
Partially correct |
13 |
Partially correct |
11 ms |
344 KB |
Partially correct |
14 |
Partially correct |
11 ms |
344 KB |
Partially correct |
15 |
Partially correct |
31 ms |
344 KB |
Partially correct |
16 |
Partially correct |
19 ms |
344 KB |
Partially correct |
17 |
Partially correct |
29 ms |
344 KB |
Partially correct |
18 |
Partially correct |
42 ms |
344 KB |
Partially correct |
19 |
Partially correct |
15 ms |
344 KB |
Partially correct |
20 |
Partially correct |
9 ms |
344 KB |
Partially correct |
21 |
Partially correct |
7 ms |
344 KB |
Partially correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
#experiments: 1 |
2 |
Correct |
0 ms |
444 KB |
#experiments: 1 |
3 |
Partially correct |
1 ms |
344 KB |
Partially correct |
4 |
Partially correct |
0 ms |
344 KB |
Partially correct |
5 |
Partially correct |
1 ms |
344 KB |
Partially correct |
6 |
Partially correct |
2 ms |
344 KB |
Partially correct |
7 |
Partially correct |
4 ms |
344 KB |
Partially correct |
8 |
Partially correct |
3 ms |
344 KB |
Partially correct |
9 |
Partially correct |
5 ms |
344 KB |
Partially correct |
10 |
Partially correct |
3 ms |
344 KB |
Partially correct |
11 |
Partially correct |
2 ms |
344 KB |
Partially correct |
12 |
Partially correct |
1 ms |
344 KB |
Partially correct |
13 |
Partially correct |
41 ms |
1208 KB |
Partially correct |
14 |
Partially correct |
119 ms |
1112 KB |
Partially correct |
15 |
Partially correct |
150 ms |
1324 KB |
Partially correct |
16 |
Partially correct |
166 ms |
1204 KB |
Partially correct |
17 |
Partially correct |
192 ms |
1112 KB |
Partially correct |
18 |
Partially correct |
146 ms |
1112 KB |
Partially correct |
19 |
Partially correct |
127 ms |
1368 KB |
Partially correct |
20 |
Partially correct |
19 ms |
1216 KB |
Partially correct |
21 |
Partially correct |
33 ms |
1112 KB |
Partially correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Partially correct |
0 ms |
344 KB |
Partially correct |
2 |
Correct |
0 ms |
344 KB |
#experiments: 1 |
3 |
Correct |
0 ms |
444 KB |
#experiments: 1 |
4 |
Partially correct |
1 ms |
344 KB |
Partially correct |
5 |
Partially correct |
0 ms |
344 KB |
Partially correct |
6 |
Partially correct |
1 ms |
344 KB |
Partially correct |
7 |
Partially correct |
1 ms |
344 KB |
Partially correct |
8 |
Partially correct |
2 ms |
344 KB |
Partially correct |
9 |
Partially correct |
1 ms |
344 KB |
Partially correct |
10 |
Partially correct |
2 ms |
344 KB |
Partially correct |
11 |
Partially correct |
2 ms |
344 KB |
Partially correct |
12 |
Partially correct |
1 ms |
344 KB |
Partially correct |
13 |
Partially correct |
1 ms |
344 KB |
Partially correct |
14 |
Partially correct |
1 ms |
344 KB |
Partially correct |
15 |
Partially correct |
2 ms |
344 KB |
Partially correct |
16 |
Partially correct |
4 ms |
344 KB |
Partially correct |
17 |
Partially correct |
3 ms |
344 KB |
Partially correct |
18 |
Partially correct |
5 ms |
344 KB |
Partially correct |
19 |
Partially correct |
3 ms |
344 KB |
Partially correct |
20 |
Partially correct |
2 ms |
344 KB |
Partially correct |
21 |
Partially correct |
1 ms |
344 KB |
Partially correct |
22 |
Partially correct |
1 ms |
344 KB |
Partially correct |
23 |
Partially correct |
1 ms |
344 KB |
Partially correct |
24 |
Partially correct |
1 ms |
344 KB |
Partially correct |
25 |
Partially correct |
2 ms |
344 KB |
Partially correct |
26 |
Partially correct |
2 ms |
344 KB |
Partially correct |
27 |
Partially correct |
1 ms |
344 KB |
Partially correct |
28 |
Partially correct |
1 ms |
344 KB |
Partially correct |
29 |
Partially correct |
2 ms |
344 KB |
Partially correct |
30 |
Partially correct |
2 ms |
344 KB |
Partially correct |
31 |
Partially correct |
2 ms |
344 KB |
Partially correct |
32 |
Partially correct |
3 ms |
344 KB |
Partially correct |
33 |
Partially correct |
1 ms |
344 KB |
Partially correct |
34 |
Partially correct |
1 ms |
344 KB |
Partially correct |
35 |
Partially correct |
11 ms |
344 KB |
Partially correct |
36 |
Partially correct |
11 ms |
344 KB |
Partially correct |
37 |
Partially correct |
31 ms |
344 KB |
Partially correct |
38 |
Partially correct |
19 ms |
344 KB |
Partially correct |
39 |
Partially correct |
29 ms |
344 KB |
Partially correct |
40 |
Partially correct |
42 ms |
344 KB |
Partially correct |
41 |
Partially correct |
15 ms |
344 KB |
Partially correct |
42 |
Partially correct |
9 ms |
344 KB |
Partially correct |
43 |
Partially correct |
7 ms |
344 KB |
Partially correct |
44 |
Partially correct |
41 ms |
1208 KB |
Partially correct |
45 |
Partially correct |
119 ms |
1112 KB |
Partially correct |
46 |
Partially correct |
150 ms |
1324 KB |
Partially correct |
47 |
Partially correct |
166 ms |
1204 KB |
Partially correct |
48 |
Partially correct |
192 ms |
1112 KB |
Partially correct |
49 |
Partially correct |
146 ms |
1112 KB |
Partially correct |
50 |
Partially correct |
127 ms |
1368 KB |
Partially correct |
51 |
Partially correct |
19 ms |
1216 KB |
Partially correct |
52 |
Partially correct |
33 ms |
1112 KB |
Partially correct |
53 |
Partially correct |
43 ms |
344 KB |
Partially correct |
54 |
Partially correct |
53 ms |
344 KB |
Partially correct |
55 |
Partially correct |
52 ms |
344 KB |
Partially correct |
56 |
Partially correct |
48 ms |
344 KB |
Partially correct |
57 |
Partially correct |
17 ms |
600 KB |
Partially correct |
58 |
Partially correct |
18 ms |
600 KB |
Partially correct |
59 |
Partially correct |
11 ms |
600 KB |
Partially correct |
60 |
Partially correct |
21 ms |
600 KB |
Partially correct |
61 |
Partially correct |
16 ms |
344 KB |
Partially correct |
62 |
Partially correct |
7 ms |
344 KB |
Partially correct |
63 |
Partially correct |
6 ms |
344 KB |
Partially correct |
64 |
Partially correct |
58 ms |
344 KB |
Partially correct |
65 |
Partially correct |
62 ms |
344 KB |
Partially correct |
66 |
Partially correct |
62 ms |
344 KB |
Partially correct |
67 |
Partially correct |
44 ms |
344 KB |
Partially correct |
68 |
Partially correct |
62 ms |
344 KB |
Partially correct |
69 |
Partially correct |
49 ms |
344 KB |
Partially correct |
70 |
Partially correct |
46 ms |
596 KB |
Partially correct |
71 |
Partially correct |
65 ms |
344 KB |
Partially correct |
72 |
Partially correct |
30 ms |
344 KB |
Partially correct |
73 |
Partially correct |
48 ms |
344 KB |
Partially correct |
74 |
Partially correct |
37 ms |
344 KB |
Partially correct |
75 |
Partially correct |
48 ms |
344 KB |
Partially correct |
76 |
Partially correct |
47 ms |
568 KB |
Partially correct |
77 |
Partially correct |
67 ms |
340 KB |
Partially correct |
78 |
Partially correct |
51 ms |
344 KB |
Partially correct |
79 |
Partially correct |
63 ms |
852 KB |
Partially correct |
80 |
Partially correct |
81 ms |
600 KB |
Partially correct |
81 |
Partially correct |
56 ms |
600 KB |
Partially correct |
82 |
Partially correct |
20 ms |
600 KB |
Partially correct |
83 |
Partially correct |
134 ms |
856 KB |
Partially correct |
84 |
Partially correct |
112 ms |
1360 KB |
Partially correct |
85 |
Partially correct |
11 ms |
600 KB |
Partially correct |
86 |
Partially correct |
20 ms |
600 KB |
Partially correct |