#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;
static const int N = 1e4+5;
static int par[N];
static int find(int x) { return par[x] = x == par[x] ? x : find(par[x]); }
static vector<pii> t[N];
static vector<int> g[N];
static int idx, pre[N], pos[N], deg[N];
static void dfs(int u, int p) {
pre[u] = idx++;
for(int v : g[u]) if(v != p) dfs(v, u);
}
static void extend_tree(int u, int p) {
if(pre[u] < 60) return;
int leaf;
vector<pii> tree = t[p];
for(pii e : tree) ++deg[e.x], ++deg[e.y];
for(pii e : tree) {
int a, b; tie(a, b) = e;
if(deg[a] == 1 || deg[b] == 1) {
leaf = deg[a] == 1 ? a : b;
break;
}
}
pos[u] = pos[leaf];
for(pii e : tree) {
--deg[e.x], --deg[e.y];
if(e.x == leaf || e.y == leaf) continue;
t[u].emplace_back(e);
}
t[u].emplace_back(u, p);
for(int v : g[u]) if(v != p) extend_tree(v, u);
}
static void solve(int n, int m, int A[], int B[]) {
iota(par, par+N, 0);
vector<pii> E, ret, init;
for(int i = 0; i < m; i++) E.emplace_back(A[i], B[i]);
sort(E.begin(), E.end());
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(pii e : ret) if(pre[e.x] < 60 && pre[e.y] < 60) init.emplace_back(e);
for(int i = 0; i < n; i++) if(pre[i] < 60) {
pos[i] = pre[i];
t[i] = init;
}
for(int i = 0; i < n; i++) if(pre[i] < 60) for(int v : g[i]) extend_tree(v, i);
}
void Joi(int N, int M, int A[], int B[], long X, int T) {
solve(N, M, A, B);
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;
static const int N = 1e4+5;
static int par[N];
static int find(int x) { return par[x] = x == par[x] ? x : find(par[x]); }
static vector<pii> t[N];
static vector<int> g[N];
static int idx, pre[N], pos[N], deg[N];
static void dfs(int u, int p) {
pre[u] = idx++;
for(int v : g[u]) if(v != p) dfs(v, u);
}
static void extend_tree(int u, int p) {
if(pre[u] < 60) return;
int leaf;
vector<pii> tree = t[p];
for(pii e : tree) ++deg[e.x], ++deg[e.y];
for(pii e : tree) {
int a, b; tie(a, b) = e;
if(deg[a] == 1 || deg[b] == 1) {
leaf = deg[a] == 1 ? a : b;
break;
}
}
pos[u] = pos[leaf];
for(pii e : tree) {
--deg[e.x], --deg[e.y];
if(e.x == leaf || e.y == leaf) continue;
t[u].emplace_back(e);
}
t[u].emplace_back(u, p);
for(int v : g[u]) if(v != p) extend_tree(v, u);
}
static void solve(int n, int m, int A[], int B[]) {
iota(par, par+N, 0);
vector<pii> E, ret, init;
for(int i = 0; i < m; i++) E.emplace_back(A[i], B[i]);
sort(E.begin(), E.end());
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(pii e : ret) if(pre[e.x] < 60 && pre[e.y] < 60) init.emplace_back(e);
for(int i = 0; i < n; i++) if(pre[i] < 60) {
pos[i] = pre[i];
t[i] = init;
}
for(int i = 0; i < n; i++) if(pre[i] < 60) for(int v : g[i]) extend_tree(v, i);
}
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) {
solve(N, M, A, B);
for(int i = 0; i < N; i++) g[i].clear();
for(pii e : t[P]) g[e.x].emplace_back(e.y), g[e.y].emplace_back(e.x);
if(V) ans += 1ll << pos[P];
get_ans(P, P);
return ans;
}
Compilation message
Joi.cpp: In function 'void extend_tree(int, int)':
Joi.cpp:39: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:39:22: warning: 'leaf' may be used uninitialized in this function [-Wmaybe-uninitialized]
pos[u] = pos[leaf];
~~~~~~~~^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
1988 KB |
Output is correct |
2 |
Correct |
4 ms |
1832 KB |
Output is correct |
3 |
Correct |
6 ms |
2188 KB |
Output is correct |
4 |
Incorrect |
5 ms |
2048 KB |
Wrong Answer [7] |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
63 ms |
14808 KB |
Output is correct |
2 |
Correct |
81 ms |
14816 KB |
Output is correct |
3 |
Correct |
87 ms |
14884 KB |
Output is correct |
4 |
Correct |
68 ms |
13976 KB |
Output is correct |
5 |
Correct |
71 ms |
18892 KB |
Output is correct |
6 |
Correct |
61 ms |
17552 KB |
Output is correct |
7 |
Correct |
62 ms |
17464 KB |
Output is correct |
8 |
Correct |
67 ms |
18112 KB |
Output is correct |
9 |
Correct |
57 ms |
18192 KB |
Output is correct |
10 |
Correct |
49 ms |
14020 KB |
Output is correct |
11 |
Correct |
63 ms |
14156 KB |
Output is correct |
12 |
Correct |
60 ms |
12940 KB |
Output is correct |
13 |
Correct |
56 ms |
13004 KB |
Output is correct |
14 |
Correct |
68 ms |
13352 KB |
Output is correct |
15 |
Correct |
56 ms |
13968 KB |
Output is correct |
16 |
Correct |
56 ms |
13920 KB |
Output is correct |
17 |
Correct |
88 ms |
14008 KB |
Output is correct |
18 |
Correct |
77 ms |
14040 KB |
Output is correct |
19 |
Correct |
58 ms |
13976 KB |
Output is correct |
20 |
Correct |
50 ms |
19360 KB |
Output is correct |
21 |
Correct |
48 ms |
19224 KB |
Output is correct |
22 |
Correct |
66 ms |
16616 KB |
Output is correct |
23 |
Correct |
72 ms |
18224 KB |
Output is correct |
24 |
Correct |
73 ms |
17148 KB |
Output is correct |
25 |
Correct |
64 ms |
17712 KB |
Output is correct |
26 |
Correct |
80 ms |
18432 KB |
Output is correct |
27 |
Correct |
64 ms |
18308 KB |
Output is correct |
28 |
Correct |
68 ms |
18360 KB |
Output is correct |
29 |
Correct |
94 ms |
16612 KB |
Output is correct |
30 |
Correct |
63 ms |
17052 KB |
Output is correct |
31 |
Correct |
7 ms |
2176 KB |
Output is correct |
32 |
Correct |
7 ms |
2184 KB |
Output is correct |
33 |
Correct |
7 ms |
2188 KB |
Output is correct |
34 |
Correct |
6 ms |
2056 KB |
Output is correct |
35 |
Correct |
6 ms |
1928 KB |
Output is correct |
36 |
Correct |
6 ms |
1928 KB |
Output is correct |
37 |
Correct |
7 ms |
1972 KB |
Output is correct |
38 |
Correct |
6 ms |
1928 KB |
Output is correct |
39 |
Correct |
6 ms |
1968 KB |
Output is correct |
40 |
Correct |
6 ms |
1956 KB |
Output is correct |
41 |
Correct |
6 ms |
2048 KB |
Output is correct |
42 |
Correct |
6 ms |
1964 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
1792 KB |
Output is correct |
2 |
Correct |
6 ms |
1936 KB |
Output is correct |
3 |
Correct |
6 ms |
1928 KB |
Output is correct |
4 |
Correct |
14 ms |
5532 KB |
Output is correct |
5 |
Correct |
15 ms |
5512 KB |
Output is correct |
6 |
Correct |
25 ms |
5532 KB |
Output is correct |
7 |
Correct |
19 ms |
5608 KB |
Output is correct |
8 |
Correct |
17 ms |
5404 KB |
Output is correct |
9 |
Correct |
64 ms |
24504 KB |
Output is correct |
10 |
Correct |
62 ms |
24504 KB |
Output is correct |
11 |
Correct |
55 ms |
24484 KB |
Output is correct |
12 |
Correct |
6 ms |
1972 KB |
Output is correct |
13 |
Correct |
6 ms |
1828 KB |
Output is correct |
14 |
Correct |
7 ms |
1976 KB |
Output is correct |
15 |
Correct |
5 ms |
1792 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
75 ms |
14772 KB |
Output is correct |
2 |
Correct |
68 ms |
14876 KB |
Output is correct |
3 |
Correct |
71 ms |
15036 KB |
Output is correct |
4 |
Correct |
60 ms |
13920 KB |
Output is correct |
5 |
Incorrect |
64 ms |
21744 KB |
Wrong Answer [7] |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
72 ms |
14760 KB |
Output is correct |
2 |
Correct |
92 ms |
14864 KB |
Output is correct |
3 |
Correct |
75 ms |
14772 KB |
Output is correct |
4 |
Correct |
77 ms |
13848 KB |
Output is correct |
5 |
Incorrect |
76 ms |
23032 KB |
Wrong Answer [7] |
6 |
Halted |
0 ms |
0 KB |
- |