#include "Joi.h"
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for (auto i = (a); i < (b); ++i)
#define all(x) begin(x), end(x)
using ll = long long;
namespace {
const int N = 1 << 14, B = 60;
int nxt[N];
int head(int u) { return nxt[u] != u ? nxt[u] = head(nxt[u]) : u; }
bool unite(int u, int v) {
u = head(u); v = head(v);
if (u == v) return 0;
nxt[u] = v; return 1;
}
vector<int> g[N];
int timer = 0; ll x;
void dfs(int u, int p) {
MessageBoard(u, x >> timer & 1);
if (++timer == B) timer = 0;
for (int v : g[u]) if (v != p) dfs(v, u);
}
}
void Joi(int n, int m, int a[], int b[], ll X, int t) {
rep(u, 0, n) nxt[u] = u;
rep(e, 0, m) {
if (unite(a[e], b[e])) {
g[a[e]].push_back(b[e]);
g[b[e]].push_back(a[e]);
}
}
x = X; dfs(0, -1);
}
#include "Ioi.h"
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for (auto i = (a); i < (b); ++i)
#define all(x) begin(x), end(x)
using ll = long long;
namespace {
const int N = 1 << 14, B = 60;
int nxt[N];
int head(int u) { return nxt[u] != u ? nxt[u] = head(nxt[u]) : u; }
bool unite(int u, int v) {
u = head(u); v = head(v);
if (u == v) return 0;
nxt[u] = v; return 1;
}
vector<int> g[N];
int p[N], in[N], timer = 0;
void init(int u) {
in[u] = timer;
if (++timer == B) timer = 0;
for (int v : g[u]) {
g[v].erase(find(all(g[v]), u));
p[v] = u; init(v);
}
}
const ll U = (1ll << B) - 1;
int cnt; ll cur;
void dummy_move() { ++cnt; }
bool dummy_add(int u) {
cur |= 1ll << in[u];
return cur == U;
}
bool dummy_dfs(int u) {
dummy_add(u);
if (cur == U) return 1;
for (int v : g[u]) {
dummy_move();
if (dummy_dfs(v)) return 1;
dummy_move();
}
return 0;
}
ll x = 0;
bool add(int u, ll z) {
cur |= 1ll << in[u];
x |= z << in[u];
return cur == U;
}
bool dfs(int u, ll z) {
if (add(u, z)) return 1;
for (int v : g[u]) {
if (dfs(v, Move(v))) return 1;
Move(u);
}
return 0;
}
}
ll Ioi(int n, int m, int a[], int b[], int P, int V, int T) {
rep(u, 0, n) nxt[u] = u;
rep(e, 0, m) {
if (unite(a[e], b[e])) {
g[a[e]].push_back(b[e]);
g[b[e]].push_back(a[e]);
}
}
init(0);
int s = -1;
rep(i, 0, 2 * B + 1) {
int u = P; cur = cnt = 0;
rep(j, 0, i) dummy_add(u), dummy_move(), u = p[u];
if (!dummy_dfs(u)) continue;
if (cnt > 2 * B) continue;
s = u; break;
}
assert(0 <= s);
cur = 0;
while (P != s) add(P, V), V = Move(p[P]), P = p[P];
dfs(P, V);
return x;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
1784 KB |
Output is correct |
2 |
Correct |
2 ms |
1544 KB |
Output is correct |
3 |
Correct |
2 ms |
1552 KB |
Output is correct |
4 |
Correct |
2 ms |
1768 KB |
Output is correct |
5 |
Correct |
2 ms |
1544 KB |
Output is correct |
6 |
Correct |
2 ms |
1544 KB |
Output is correct |
7 |
Correct |
2 ms |
1776 KB |
Output is correct |
8 |
Correct |
2 ms |
1600 KB |
Output is correct |
9 |
Correct |
2 ms |
1756 KB |
Output is correct |
10 |
Correct |
2 ms |
1672 KB |
Output is correct |
11 |
Runtime error |
6 ms |
2604 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
12 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
27 ms |
4064 KB |
Output is correct |
2 |
Correct |
27 ms |
4160 KB |
Output is correct |
3 |
Correct |
28 ms |
4168 KB |
Output is correct |
4 |
Correct |
16 ms |
3408 KB |
Output is correct |
5 |
Correct |
16 ms |
3756 KB |
Output is correct |
6 |
Correct |
18 ms |
3644 KB |
Output is correct |
7 |
Correct |
17 ms |
3756 KB |
Output is correct |
8 |
Correct |
17 ms |
3868 KB |
Output is correct |
9 |
Correct |
23 ms |
3876 KB |
Output is correct |
10 |
Correct |
20 ms |
3628 KB |
Output is correct |
11 |
Correct |
18 ms |
3376 KB |
Output is correct |
12 |
Correct |
16 ms |
3336 KB |
Output is correct |
13 |
Correct |
15 ms |
3220 KB |
Output is correct |
14 |
Correct |
17 ms |
3444 KB |
Output is correct |
15 |
Correct |
18 ms |
3404 KB |
Output is correct |
16 |
Correct |
17 ms |
3412 KB |
Output is correct |
17 |
Correct |
17 ms |
3400 KB |
Output is correct |
18 |
Correct |
18 ms |
3244 KB |
Output is correct |
19 |
Correct |
22 ms |
3404 KB |
Output is correct |
20 |
Correct |
14 ms |
3960 KB |
Output is correct |
21 |
Correct |
15 ms |
3756 KB |
Output is correct |
22 |
Correct |
17 ms |
3684 KB |
Output is correct |
23 |
Correct |
18 ms |
3628 KB |
Output is correct |
24 |
Correct |
17 ms |
3664 KB |
Output is correct |
25 |
Correct |
17 ms |
3644 KB |
Output is correct |
26 |
Correct |
17 ms |
3876 KB |
Output is correct |
27 |
Correct |
17 ms |
3628 KB |
Output is correct |
28 |
Correct |
17 ms |
3864 KB |
Output is correct |
29 |
Correct |
17 ms |
3568 KB |
Output is correct |
30 |
Correct |
15 ms |
3488 KB |
Output is correct |
31 |
Correct |
2 ms |
1544 KB |
Output is correct |
32 |
Correct |
2 ms |
1776 KB |
Output is correct |
33 |
Correct |
2 ms |
1552 KB |
Output is correct |
34 |
Correct |
2 ms |
1784 KB |
Output is correct |
35 |
Correct |
2 ms |
1660 KB |
Output is correct |
36 |
Correct |
2 ms |
1788 KB |
Output is correct |
37 |
Correct |
2 ms |
1544 KB |
Output is correct |
38 |
Runtime error |
2 ms |
2184 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
39 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
1772 KB |
Output is correct |
2 |
Correct |
2 ms |
1648 KB |
Output is correct |
3 |
Correct |
2 ms |
1788 KB |
Output is correct |
4 |
Correct |
4 ms |
1972 KB |
Output is correct |
5 |
Correct |
3 ms |
1844 KB |
Output is correct |
6 |
Correct |
4 ms |
2000 KB |
Output is correct |
7 |
Correct |
3 ms |
1844 KB |
Output is correct |
8 |
Correct |
4 ms |
2008 KB |
Output is correct |
9 |
Correct |
15 ms |
4268 KB |
Output is correct |
10 |
Correct |
15 ms |
4268 KB |
Output is correct |
11 |
Correct |
13 ms |
4344 KB |
Output is correct |
12 |
Correct |
2 ms |
1544 KB |
Output is correct |
13 |
Correct |
2 ms |
1544 KB |
Output is correct |
14 |
Correct |
2 ms |
1788 KB |
Output is correct |
15 |
Correct |
2 ms |
1544 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
28 ms |
4156 KB |
Output is correct |
2 |
Correct |
28 ms |
4332 KB |
Output is correct |
3 |
Correct |
27 ms |
3992 KB |
Output is correct |
4 |
Correct |
17 ms |
3372 KB |
Output is correct |
5 |
Correct |
17 ms |
4012 KB |
Output is correct |
6 |
Correct |
17 ms |
3628 KB |
Output is correct |
7 |
Correct |
20 ms |
3880 KB |
Output is correct |
8 |
Correct |
20 ms |
3700 KB |
Output is correct |
9 |
Correct |
27 ms |
3500 KB |
Output is correct |
10 |
Correct |
19 ms |
3620 KB |
Output is correct |
11 |
Correct |
20 ms |
3632 KB |
Output is correct |
12 |
Correct |
15 ms |
3348 KB |
Output is correct |
13 |
Correct |
16 ms |
3332 KB |
Output is correct |
14 |
Correct |
15 ms |
3436 KB |
Output is correct |
15 |
Correct |
18 ms |
3420 KB |
Output is correct |
16 |
Correct |
17 ms |
3244 KB |
Output is correct |
17 |
Correct |
19 ms |
3404 KB |
Output is correct |
18 |
Correct |
16 ms |
3244 KB |
Output is correct |
19 |
Correct |
16 ms |
3372 KB |
Output is correct |
20 |
Correct |
14 ms |
3756 KB |
Output is correct |
21 |
Correct |
15 ms |
3836 KB |
Output is correct |
22 |
Correct |
18 ms |
3628 KB |
Output is correct |
23 |
Correct |
18 ms |
3656 KB |
Output is correct |
24 |
Correct |
17 ms |
3500 KB |
Output is correct |
25 |
Correct |
18 ms |
3892 KB |
Output is correct |
26 |
Correct |
17 ms |
3628 KB |
Output is correct |
27 |
Correct |
18 ms |
3852 KB |
Output is correct |
28 |
Correct |
18 ms |
3628 KB |
Output is correct |
29 |
Correct |
16 ms |
3476 KB |
Output is correct |
30 |
Correct |
17 ms |
3660 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
28 ms |
3992 KB |
Output is correct |
2 |
Correct |
27 ms |
4168 KB |
Output is correct |
3 |
Correct |
28 ms |
4120 KB |
Output is correct |
4 |
Correct |
17 ms |
3404 KB |
Output is correct |
5 |
Correct |
17 ms |
4140 KB |
Output is correct |
6 |
Correct |
17 ms |
3664 KB |
Output is correct |
7 |
Correct |
16 ms |
3500 KB |
Output is correct |
8 |
Correct |
17 ms |
3868 KB |
Output is correct |
9 |
Correct |
17 ms |
3628 KB |
Output is correct |
10 |
Correct |
15 ms |
3628 KB |
Output is correct |
11 |
Correct |
15 ms |
3376 KB |
Output is correct |
12 |
Correct |
16 ms |
3344 KB |
Output is correct |
13 |
Correct |
15 ms |
3340 KB |
Output is correct |
14 |
Correct |
17 ms |
3436 KB |
Output is correct |
15 |
Correct |
16 ms |
3428 KB |
Output is correct |
16 |
Correct |
16 ms |
3412 KB |
Output is correct |
17 |
Correct |
17 ms |
3372 KB |
Output is correct |
18 |
Correct |
18 ms |
3408 KB |
Output is correct |
19 |
Correct |
19 ms |
3400 KB |
Output is correct |
20 |
Correct |
15 ms |
3756 KB |
Output is correct |
21 |
Correct |
13 ms |
3840 KB |
Output is correct |
22 |
Correct |
17 ms |
3500 KB |
Output is correct |
23 |
Correct |
17 ms |
3664 KB |
Output is correct |
24 |
Correct |
19 ms |
3664 KB |
Output is correct |
25 |
Correct |
17 ms |
3628 KB |
Output is correct |
26 |
Correct |
17 ms |
3500 KB |
Output is correct |
27 |
Correct |
20 ms |
3732 KB |
Output is correct |
28 |
Correct |
18 ms |
3840 KB |
Output is correct |
29 |
Correct |
18 ms |
3616 KB |
Output is correct |
30 |
Correct |
17 ms |
3616 KB |
Output is correct |
31 |
Correct |
2 ms |
1672 KB |
Output is correct |
32 |
Correct |
2 ms |
1772 KB |
Output is correct |
33 |
Correct |
2 ms |
1552 KB |
Output is correct |
34 |
Correct |
2 ms |
1784 KB |
Output is correct |
35 |
Correct |
2 ms |
1544 KB |
Output is correct |
36 |
Correct |
2 ms |
1544 KB |
Output is correct |
37 |
Correct |
2 ms |
1544 KB |
Output is correct |
38 |
Runtime error |
3 ms |
2444 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
39 |
Halted |
0 ms |
0 KB |
- |