#include "Joi.h"
#include <bits/stdc++.h>
#define long long long
#define pii pair<int, int>
#define x first
#define y second
using namespace std;
const int N = 1e4+5;
static vector<int> g[N];
static vector<pii> init;
static int pre[N], pos[N];
static void dfs(int u, int p) {
static int idx = 0;
pre[u] = idx++;
for(int v : g[u]) if(v != p) dfs(v, u);
}
static void gen_tree(int n, int m, int A[], int B[]) {
int par[N]; iota(par, par+N, 0);
vector<pii> E;
function<int(int)> find = [&](int x) { return par[x] = x == par[x] ? x : find(par[x]); };
for(int i = 0; i < m; i++) {
if(A[i] > B[i]) swap(A[i], B[i]);
E.emplace_back(A[i], B[i]);
}
sort(E.begin(), E.end());
vector<pii> ret;
for(pii e : E) {
int a, b; tie(a, b) = e;
if(find(a) != find(b)) {
par[find(a)] = find(b);
g[a].emplace_back(b), g[b].emplace_back(a);
ret.emplace_back(a, b);
}
}
dfs(0, 0);
for(int i = 0; i < n; i++) if(pre[i] < 60) pos[i] = pre[i];
for(pii e : ret) {
int a, b; tie(a, b) = e;
if(pre[a] < 60 && pre[b] < 60) init.emplace_back(a, b);
}
}
static int deg[N];
static vector<pii> t[N];
static void extend_tree(int u, int p) {
if(pre[u] < 60) return;
vector<pii> v = t[p];
assert(!v.empty());
for(pii e : v) {
int a, b; tie(a, b) = e;
++deg[a], ++deg[b];
}
int leaf;
for(pii e : v) {
int a, b; tie(a, b) = e;
if(deg[a] > deg[b]) swap(a, b);
if(deg[a] == 1) { leaf = a; break; }
}
pos[u] = pos[leaf];
for(pii e : v) {
int a, b; tie(a, b) = e;
--deg[a], --deg[b];
if(a == leaf || b == leaf) continue;
t[u].emplace_back(a, b);
}
t[u].emplace_back(u, p);
for(int v : g[u]) if(v != p) extend_tree(v, u);
}
void Joi(int n, int m, int A[], int B[], long x, int T) {
gen_tree(n, m, A, B);
for(int i = 0; i < n; i++) if(pre[i] < 60) t[i] = init;
for(int i = 0; i < n; i++) if(pre[i] < 60) for(int v : g[i]) extend_tree(v, i);
for(int i = 0; i < n; i++) MessageBoard(i, x >> pos[i] & 1);
}
#include "Ioi.h"
#include <bits/stdc++.h>
#define long long long
#define pii pair<int, int>
#define x first
#define y second
using namespace std;
const int N = 1e4+5;
static vector<int> g[N];
static vector<pii> init;
static int pre[N], pos[N];
static void dfs(int u, int p) {
static int idx = 0;
pre[u] = idx++;
for(int v : g[u]) if(v != p) dfs(v, u);
}
static void gen_tree(int n, int m, int A[], int B[]) {
int par[N]; iota(par, par+N, 0);
vector<pii> E;
function<int(int)> find = [&](int x) { return par[x] = x == par[x] ? x : find(par[x]); };
for(int i = 0; i < m; i++) {
if(A[i] > B[i]) swap(A[i], B[i]);
E.emplace_back(A[i], B[i]);
}
sort(E.begin(), E.end());
vector<pii> ret;
for(pii e : E) {
int a, b; tie(a, b) = e;
if(find(a) != find(b)) {
par[find(a)] = find(b);
g[a].emplace_back(b), g[b].emplace_back(a);
ret.emplace_back(a, b);
}
}
dfs(0, 0);
for(int i = 0; i < n; i++) if(pre[i] < 60) pos[i] = pre[i];
for(pii e : ret) {
int a, b; tie(a, b) = e;
if(pre[a] < 60 && pre[b] < 60) init.emplace_back(a, b);
}
}
static int deg[N];
static vector<pii> t[N];
static void extend_tree(int u, int p) {
if(pre[u] < 60) return;
vector<pii> v = t[p];
for(pii e : v) {
int a, b; tie(a, b) = e;
++deg[a], ++deg[b];
}
int leaf;
for(pii e : v) {
int a, b; tie(a, b) = e;
if(deg[a] > deg[b]) swap(a, b);
if(deg[a] == 1) { leaf = a; break; }
}
pos[u] = pos[leaf];
for(pii e : v) {
int a, b; tie(a, b) = e;
--deg[a], --deg[b];
if(a == leaf || b == leaf) continue;
t[u].emplace_back(a, b);
}
t[u].emplace_back(u, p);
for(int v : g[u]) if(v != p) extend_tree(v, u);
}
static long ans;
static void get_ans(int u, int p) {
for(int v : g[u]) if(v != p) {
int nex = Move(v);
if(nex) ans += 1ll << pos[v];
get_ans(v, u);
Move(u);
}
}
long Ioi(int n, int m, int A[], int B[], int P, int V, int T) {
gen_tree(n, m, A, B);
for(int i = 0; i < n; i++) if(pre[i] < 60) t[i] = init;
for(int i = 0; i < n; i++) if(pre[i] < 60) for(int v : g[i]) extend_tree(v, i);
for(int i = 0; i < n; i++) g[i].clear();
if(V) ans += 1ll << pos[P];
for(pii e : t[P]) g[e.x].emplace_back(e.y), g[e.y].emplace_back(e.x);
get_ans(P, P);
return ans;
}
Compilation message
Joi.cpp: In function 'void extend_tree(int, int)':
Joi.cpp:69:22: warning: 'leaf' may be used uninitialized in this function [-Wmaybe-uninitialized]
pos[u] = pos[leaf];
~~~~~~~~^
Ioi.cpp: In function 'void extend_tree(int, int)':
Ioi.cpp:68:22: warning: 'leaf' may be used uninitialized in this function [-Wmaybe-uninitialized]
pos[u] = pos[leaf];
~~~~~~~~^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
1844 KB |
Output is correct |
2 |
Correct |
5 ms |
1920 KB |
Output is correct |
3 |
Correct |
7 ms |
2180 KB |
Output is correct |
4 |
Correct |
6 ms |
1792 KB |
Output is correct |
5 |
Correct |
6 ms |
1920 KB |
Output is correct |
6 |
Correct |
6 ms |
2164 KB |
Output is correct |
7 |
Correct |
7 ms |
2180 KB |
Output is correct |
8 |
Correct |
6 ms |
2180 KB |
Output is correct |
9 |
Correct |
7 ms |
2060 KB |
Output is correct |
10 |
Correct |
6 ms |
1956 KB |
Output is correct |
11 |
Correct |
9 ms |
2152 KB |
Output is correct |
12 |
Correct |
6 ms |
1876 KB |
Output is correct |
13 |
Correct |
10 ms |
2180 KB |
Output is correct |
14 |
Correct |
7 ms |
2052 KB |
Output is correct |
15 |
Correct |
8 ms |
2060 KB |
Output is correct |
16 |
Correct |
7 ms |
2216 KB |
Output is correct |
17 |
Correct |
6 ms |
2232 KB |
Output is correct |
18 |
Correct |
7 ms |
2220 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
83 ms |
14508 KB |
Output is correct |
2 |
Correct |
87 ms |
14460 KB |
Output is correct |
3 |
Correct |
94 ms |
14516 KB |
Output is correct |
4 |
Correct |
65 ms |
13760 KB |
Output is correct |
5 |
Correct |
67 ms |
18660 KB |
Output is correct |
6 |
Correct |
73 ms |
16984 KB |
Output is correct |
7 |
Correct |
72 ms |
17052 KB |
Output is correct |
8 |
Correct |
67 ms |
18028 KB |
Output is correct |
9 |
Correct |
65 ms |
18148 KB |
Output is correct |
10 |
Correct |
52 ms |
13800 KB |
Output is correct |
11 |
Correct |
44 ms |
14052 KB |
Output is correct |
12 |
Correct |
53 ms |
12560 KB |
Output is correct |
13 |
Correct |
55 ms |
12824 KB |
Output is correct |
14 |
Correct |
50 ms |
13424 KB |
Output is correct |
15 |
Correct |
70 ms |
13836 KB |
Output is correct |
16 |
Correct |
59 ms |
13744 KB |
Output is correct |
17 |
Correct |
55 ms |
13812 KB |
Output is correct |
18 |
Correct |
73 ms |
13796 KB |
Output is correct |
19 |
Correct |
76 ms |
13804 KB |
Output is correct |
20 |
Correct |
61 ms |
19152 KB |
Output is correct |
21 |
Correct |
50 ms |
18680 KB |
Output is correct |
22 |
Correct |
63 ms |
16520 KB |
Output is correct |
23 |
Correct |
68 ms |
17860 KB |
Output is correct |
24 |
Correct |
69 ms |
16776 KB |
Output is correct |
25 |
Correct |
125 ms |
17496 KB |
Output is correct |
26 |
Correct |
63 ms |
18148 KB |
Output is correct |
27 |
Correct |
70 ms |
17912 KB |
Output is correct |
28 |
Correct |
67 ms |
18412 KB |
Output is correct |
29 |
Correct |
53 ms |
16348 KB |
Output is correct |
30 |
Correct |
67 ms |
16784 KB |
Output is correct |
31 |
Correct |
6 ms |
2000 KB |
Output is correct |
32 |
Correct |
9 ms |
2056 KB |
Output is correct |
33 |
Correct |
9 ms |
2188 KB |
Output is correct |
34 |
Correct |
6 ms |
1920 KB |
Output is correct |
35 |
Correct |
5 ms |
1792 KB |
Output is correct |
36 |
Correct |
10 ms |
1992 KB |
Output is correct |
37 |
Correct |
6 ms |
1920 KB |
Output is correct |
38 |
Correct |
7 ms |
1920 KB |
Output is correct |
39 |
Correct |
5 ms |
1708 KB |
Output is correct |
40 |
Correct |
5 ms |
1920 KB |
Output is correct |
41 |
Correct |
6 ms |
2176 KB |
Output is correct |
42 |
Correct |
6 ms |
1920 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
1920 KB |
Output is correct |
2 |
Correct |
7 ms |
1936 KB |
Output is correct |
3 |
Correct |
5 ms |
2000 KB |
Output is correct |
4 |
Correct |
13 ms |
5412 KB |
Output is correct |
5 |
Correct |
16 ms |
5416 KB |
Output is correct |
6 |
Correct |
15 ms |
5316 KB |
Output is correct |
7 |
Correct |
14 ms |
5148 KB |
Output is correct |
8 |
Correct |
13 ms |
5276 KB |
Output is correct |
9 |
Correct |
58 ms |
24292 KB |
Output is correct |
10 |
Correct |
61 ms |
24372 KB |
Output is correct |
11 |
Correct |
56 ms |
24384 KB |
Output is correct |
12 |
Correct |
6 ms |
1956 KB |
Output is correct |
13 |
Correct |
7 ms |
1800 KB |
Output is correct |
14 |
Correct |
6 ms |
1928 KB |
Output is correct |
15 |
Correct |
6 ms |
1920 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
69 ms |
14452 KB |
Output is correct |
2 |
Incorrect |
66 ms |
14348 KB |
Wrong Answer [7] |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
83 ms |
14324 KB |
Output is correct |
2 |
Correct |
77 ms |
14304 KB |
Output is correct |
3 |
Correct |
83 ms |
14336 KB |
Output is correct |
4 |
Correct |
78 ms |
13808 KB |
Output is correct |
5 |
Incorrect |
90 ms |
22752 KB |
Wrong Answer [7] |
6 |
Halted |
0 ms |
0 KB |
- |