#include "Joi.h"
#include <vector>
#include <algorithm>
using ll = long long;
const int NMAX = 10'000;
std::vector<int> g[NMAX + 1];
int value[NMAX + 1];
bool vis[NMAX + 1];
std::vector<int> order;
void dfs(int u) {
order.push_back(u);
vis[u] = true;
for (const auto &v : g[u]) {
if (!vis[v]) {
dfs(v);
}
}
}
void Joi(int n, int m, int a[], int b[], long long X, int T) {
for (int i = 0; i < m; i++) {
g[a[i]].push_back(b[i]);
g[b[i]].push_back(a[i]);
}
for (int i = 0; i < n; i++) {
std::sort(g[i].begin(), g[i].end());
}
dfs(0);
for (int i = 0; i < 60; i++) {
value[order[i]] = ((ll) X >> i) & 1LL;
}
for (int i = 0; i < n; i++) {
MessageBoard(i, value[i]);
}
}
#include "Ioi.h"
#include <vector>
#include <algorithm>
#include <cassert>
using ll = long long;
const int NMAX = 10'000;
std::vector<int> g[NMAX + 1];
int value[NMAX + 1];
bool vis[NMAX + 1];
int parent[NMAX + 1];
std::vector<int> order;
void dfs(int u) {
order.push_back(u);
vis[u] = true;
for (const auto &v : g[u]) {
if (!vis[v]) {
parent[v] = u;
dfs(v);
}
}
}
bool hasSon(int u, int v) { // v e fiu al lui u?
for (const auto &w : g[u]) {
if (v == w) {
return true;
}
}
return false;
}
long long Ioi(int n, int m, int a[], int b[], int P, int V, int T) {
for (int i = 0; i < m; i++) {
g[a[i]].push_back(b[i]);
g[b[i]].push_back(a[i]);
}
for (int i = 0; i < n; i++) {
std::sort(g[i].begin(), g[i].end());
}
dfs(0);
int u = P;
ll answer = 0;
if (u == 0) {
Move(g[0][0]);
answer = Move(0);
}
while (u != 0) {
u = parent[u];
answer = Move(u);
}
for (int i = 1; i < 60; i++) {
while (u != 0 && !hasSon(u, order[i])) {
u = parent[u];
Move(u);
}
assert(hasSon(u, order[i]));
if (Move(order[i])) {
answer |= (1LL << i);
}
u = order[i];
}
return answer;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
1292 KB |
Output is correct |
2 |
Correct |
1 ms |
1308 KB |
Output is correct |
3 |
Correct |
1 ms |
1304 KB |
Output is correct |
4 |
Correct |
1 ms |
1308 KB |
Output is correct |
5 |
Correct |
0 ms |
1308 KB |
Output is correct |
6 |
Correct |
0 ms |
1300 KB |
Output is correct |
7 |
Correct |
1 ms |
1304 KB |
Output is correct |
8 |
Correct |
2 ms |
1312 KB |
Output is correct |
9 |
Correct |
1 ms |
1304 KB |
Output is correct |
10 |
Correct |
1 ms |
1308 KB |
Output is correct |
11 |
Correct |
3 ms |
1632 KB |
Output is correct |
12 |
Correct |
1 ms |
1304 KB |
Output is correct |
13 |
Correct |
1 ms |
1304 KB |
Output is correct |
14 |
Correct |
1 ms |
1304 KB |
Output is correct |
15 |
Correct |
1 ms |
1312 KB |
Output is correct |
16 |
Correct |
1 ms |
1304 KB |
Output is correct |
17 |
Correct |
1 ms |
1312 KB |
Output is correct |
18 |
Correct |
0 ms |
1304 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
15 ms |
4444 KB |
Output is correct |
2 |
Correct |
22 ms |
4540 KB |
Output is correct |
3 |
Correct |
17 ms |
4636 KB |
Output is correct |
4 |
Correct |
11 ms |
3128 KB |
Output is correct |
5 |
Correct |
10 ms |
3384 KB |
Output is correct |
6 |
Correct |
9 ms |
3376 KB |
Output is correct |
7 |
Correct |
9 ms |
3388 KB |
Output is correct |
8 |
Correct |
9 ms |
3356 KB |
Output is correct |
9 |
Correct |
9 ms |
3436 KB |
Output is correct |
10 |
Correct |
9 ms |
3352 KB |
Output is correct |
11 |
Correct |
10 ms |
3384 KB |
Output is correct |
12 |
Correct |
7 ms |
2844 KB |
Output is correct |
13 |
Correct |
8 ms |
2848 KB |
Output is correct |
14 |
Correct |
9 ms |
2864 KB |
Output is correct |
15 |
Correct |
9 ms |
3120 KB |
Output is correct |
16 |
Correct |
9 ms |
3048 KB |
Output is correct |
17 |
Correct |
9 ms |
3124 KB |
Output is correct |
18 |
Correct |
9 ms |
3124 KB |
Output is correct |
19 |
Correct |
11 ms |
3124 KB |
Output is correct |
20 |
Correct |
9 ms |
3660 KB |
Output is correct |
21 |
Correct |
7 ms |
3648 KB |
Output is correct |
22 |
Correct |
9 ms |
3380 KB |
Output is correct |
23 |
Correct |
9 ms |
3388 KB |
Output is correct |
24 |
Correct |
13 ms |
3480 KB |
Output is correct |
25 |
Correct |
9 ms |
3632 KB |
Output is correct |
26 |
Correct |
9 ms |
3376 KB |
Output is correct |
27 |
Correct |
9 ms |
3380 KB |
Output is correct |
28 |
Correct |
9 ms |
3384 KB |
Output is correct |
29 |
Correct |
9 ms |
3364 KB |
Output is correct |
30 |
Correct |
9 ms |
3316 KB |
Output is correct |
31 |
Correct |
0 ms |
1560 KB |
Output is correct |
32 |
Correct |
0 ms |
1300 KB |
Output is correct |
33 |
Correct |
1 ms |
1312 KB |
Output is correct |
34 |
Correct |
1 ms |
1296 KB |
Output is correct |
35 |
Correct |
0 ms |
1292 KB |
Output is correct |
36 |
Correct |
1 ms |
1308 KB |
Output is correct |
37 |
Correct |
0 ms |
1308 KB |
Output is correct |
38 |
Correct |
0 ms |
1308 KB |
Output is correct |
39 |
Correct |
0 ms |
1376 KB |
Output is correct |
40 |
Correct |
0 ms |
1296 KB |
Output is correct |
41 |
Correct |
0 ms |
1304 KB |
Output is correct |
42 |
Correct |
0 ms |
1292 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
1288 KB |
Output is correct |
2 |
Correct |
1 ms |
1292 KB |
Output is correct |
3 |
Correct |
0 ms |
1304 KB |
Output is correct |
4 |
Correct |
2 ms |
1844 KB |
Output is correct |
5 |
Incorrect |
2 ms |
1848 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
16 ms |
4444 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
17 ms |
4444 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |