#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(!t[u].empty()) 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(!t[u].empty()) 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];
~~~~~~~~^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
1920 KB |
Output is correct |
2 |
Correct |
6 ms |
1920 KB |
Output is correct |
3 |
Correct |
6 ms |
2052 KB |
Output is correct |
4 |
Incorrect |
6 ms |
1920 KB |
Wrong Answer [7] |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
72 ms |
14700 KB |
Output is correct |
2 |
Correct |
68 ms |
14768 KB |
Output is correct |
3 |
Correct |
80 ms |
14808 KB |
Output is correct |
4 |
Correct |
71 ms |
14112 KB |
Output is correct |
5 |
Correct |
84 ms |
19008 KB |
Output is correct |
6 |
Correct |
61 ms |
17304 KB |
Output is correct |
7 |
Correct |
74 ms |
17464 KB |
Output is correct |
8 |
Correct |
76 ms |
18104 KB |
Output is correct |
9 |
Correct |
66 ms |
18412 KB |
Output is correct |
10 |
Correct |
55 ms |
14156 KB |
Output is correct |
11 |
Correct |
49 ms |
14188 KB |
Output is correct |
12 |
Correct |
69 ms |
12924 KB |
Output is correct |
13 |
Correct |
56 ms |
12704 KB |
Output is correct |
14 |
Correct |
67 ms |
13352 KB |
Output is correct |
15 |
Correct |
62 ms |
13848 KB |
Output is correct |
16 |
Correct |
65 ms |
13976 KB |
Output is correct |
17 |
Correct |
62 ms |
14124 KB |
Output is correct |
18 |
Correct |
53 ms |
13976 KB |
Output is correct |
19 |
Correct |
51 ms |
13984 KB |
Output is correct |
20 |
Correct |
45 ms |
19352 KB |
Output is correct |
21 |
Correct |
61 ms |
19136 KB |
Output is correct |
22 |
Correct |
84 ms |
16952 KB |
Output is correct |
23 |
Correct |
63 ms |
18224 KB |
Output is correct |
24 |
Correct |
63 ms |
17124 KB |
Output is correct |
25 |
Correct |
66 ms |
17696 KB |
Output is correct |
26 |
Correct |
76 ms |
18320 KB |
Output is correct |
27 |
Correct |
77 ms |
18252 KB |
Output is correct |
28 |
Correct |
69 ms |
18448 KB |
Output is correct |
29 |
Correct |
66 ms |
16528 KB |
Output is correct |
30 |
Correct |
64 ms |
17040 KB |
Output is correct |
31 |
Correct |
6 ms |
2056 KB |
Output is correct |
32 |
Correct |
11 ms |
2164 KB |
Output is correct |
33 |
Correct |
7 ms |
2188 KB |
Output is correct |
34 |
Correct |
6 ms |
2168 KB |
Output is correct |
35 |
Correct |
6 ms |
2056 KB |
Output is correct |
36 |
Correct |
6 ms |
2048 KB |
Output is correct |
37 |
Correct |
7 ms |
1920 KB |
Output is correct |
38 |
Correct |
6 ms |
1928 KB |
Output is correct |
39 |
Correct |
7 ms |
1976 KB |
Output is correct |
40 |
Correct |
7 ms |
2080 KB |
Output is correct |
41 |
Correct |
6 ms |
1792 KB |
Output is correct |
42 |
Correct |
6 ms |
1920 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
1920 KB |
Output is correct |
2 |
Correct |
5 ms |
2048 KB |
Output is correct |
3 |
Correct |
5 ms |
1920 KB |
Output is correct |
4 |
Correct |
17 ms |
5532 KB |
Output is correct |
5 |
Correct |
18 ms |
5580 KB |
Output is correct |
6 |
Correct |
17 ms |
5632 KB |
Output is correct |
7 |
Correct |
15 ms |
5540 KB |
Output is correct |
8 |
Correct |
13 ms |
5484 KB |
Output is correct |
9 |
Correct |
58 ms |
24660 KB |
Output is correct |
10 |
Correct |
54 ms |
24540 KB |
Output is correct |
11 |
Correct |
53 ms |
24560 KB |
Output is correct |
12 |
Correct |
6 ms |
1928 KB |
Output is correct |
13 |
Correct |
6 ms |
1920 KB |
Output is correct |
14 |
Correct |
7 ms |
1976 KB |
Output is correct |
15 |
Correct |
6 ms |
1920 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
78 ms |
14720 KB |
Output is correct |
2 |
Correct |
77 ms |
14736 KB |
Output is correct |
3 |
Correct |
91 ms |
14756 KB |
Output is correct |
4 |
Correct |
69 ms |
13968 KB |
Output is correct |
5 |
Incorrect |
77 ms |
21776 KB |
Wrong Answer [7] |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
83 ms |
14884 KB |
Output is correct |
2 |
Correct |
101 ms |
14936 KB |
Output is correct |
3 |
Correct |
74 ms |
14752 KB |
Output is correct |
4 |
Correct |
71 ms |
13976 KB |
Output is correct |
5 |
Incorrect |
71 ms |
23004 KB |
Wrong Answer [7] |
6 |
Halted |
0 ms |
0 KB |
- |