#include "Joi.h"
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define ull unsigned long long
#define pb push_back
#define pll pair<int, pii>
#define pii pair<int, int>
#define fi first
#define se second
using namespace std;
const int N = 2e5+2;
const int M = 60;
const int mod = 1e9+7;
const ll base = 1e6;
const ll inf = 1e9;
int n, m, b[N], a[N], k, d[N], cnt, par[N], f[N];
ll ans;
vector<int> adj[N];
bool vis[N], ok;
set<pii> leaf;
set<int> st[N], cur, res;
void dfs(int u, int p = -1)
{
pii change;
set<int> stchange;
vis[u] = true;
if(cnt < M)d[u] = cnt++;
else
{
auto it = leaf.begin();
if(d[par[u]] == (*it).se)++it;
int v = (*it).se;
cur.erase(b[v]);
change.fi = v;
change.se = b[v];
d[u] = v;
leaf.erase(it);
stchange = st[v];
for(int x: st[v])
{
leaf.erase({(int)st[x].size(), x});
st[x].erase(v);
leaf.insert({(int)st[x].size(), x});
}
st[v].clear();
}
if(u != 0)leaf.insert({1, d[u]});
else leaf.insert({0, d[u]});
b[d[u]] = u;
cur.insert(u);
if(p == u)ok = true;
if(ok && cnt == M)
{
res = cur;
ok = false;
}
if(u != 0)
{
int v = d[par[u]];
leaf.erase({(int)st[v].size(), v});
st[v].insert(d[u]);
st[d[u]].insert(v);
leaf.insert({(int)st[v].size(), v});
}
//cout << u <<" "<<d[u]<<'\n';
for(int v: adj[u])
{
if(vis[v])continue;
par[v] = u;
dfs(v, p);
}
if(!stchange.empty())
{
int v = d[par[u]];
leaf.erase({(int)st[v].size(), v});
st[v].erase(d[u]);
st[d[u]].erase(v);
leaf.insert({(int)st[v].size(), v});
cur.erase(u);
leaf.erase({1, d[u]});
v = change.fi;
cur.insert(change.se);
leaf.insert({1, v});
b[v] = change.se;
for(int x: stchange)
{
leaf.erase({(int)st[x].size(), x});
st[x].insert(v);
leaf.insert({(int)st[x].size(), x});
}
st[v] = stchange;
}
}
void Joi(int n, int m, int A[], int B[], ll x, int T)
{
for(int i = 0; i < n; i ++)
{
st[i].clear();
adj[i].clear();
}
leaf.clear();
res.clear();
cur.clear();
cnt = 0;
for(int i = 0; i < m; i ++)
{
adj[A[i]].pb(B[i]);
adj[B[i]].pb(A[i]);
}
fill_n(d, n, -1);
fill_n(par, n, -1);
fill_n(vis, n, 0);
dfs(0);
for(int i = 0; i < n; i ++)
{
MessageBoard(i, (x>>d[i]&1));
}
}
#include "Ioi.h"
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define ull unsigned long long
#define pb push_back
#define pll pair<int, pii>
#define pii pair<int, int>
#define fi first
#define se second
using namespace std;
const int N = 2e5+2;
const int M = 60;
const int mod = 1e9+7;
const ll base = 1e6;
const ll inf = 1e9;
int n, m, b[N], a[N], k, d[N], cnt, par[N], f[N];
ll ans;
vector<int> adj[N];
bool vis[N], ok;
set<pii> leaf;
set<int> st[N], cur, res;
void dfs(int u, int p = -1)
{
pii change;
set<int> stchange;
vis[u] = true;
if(cnt < M)d[u] = cnt++;
else
{
auto it = leaf.begin();
if(d[par[u]] == (*it).se)++it;
int v = (*it).se;
cur.erase(b[v]);
change.fi = v;
change.se = b[v];
d[u] = v;
leaf.erase(it);
stchange = st[v];
for(int x: st[v])
{
leaf.erase({(int)st[x].size(), x});
st[x].erase(v);
leaf.insert({(int)st[x].size(), x});
}
st[v].clear();
}
if(u != 0)leaf.insert({1, d[u]});
else leaf.insert({0, d[u]});
b[d[u]] = u;
cur.insert(u);
if(p == u)ok = true;
if(ok && cnt == M)
{
res = cur;
ok = false;
}
if(u != 0)
{
int v = d[par[u]];
leaf.erase({(int)st[v].size(), v});
st[v].insert(d[u]);
st[d[u]].insert(v);
leaf.insert({(int)st[v].size(), v});
}
//cout << u <<" "<<d[u]<<'\n';
for(int v: adj[u])
{
if(vis[v])continue;
par[v] = u;
dfs(v, p);
}
if(!stchange.empty())
{
int v = d[par[u]];
leaf.erase({(int)st[v].size(), v});
st[v].erase(d[u]);
st[d[u]].erase(v);
leaf.insert({(int)st[v].size(), v});
cur.erase(u);
leaf.erase({1, d[u]});
v = change.fi;
cur.insert(change.se);
leaf.insert({1, v});
b[v] = change.se;
for(int x: stchange)
{
leaf.erase({(int)st[x].size(), x});
st[x].insert(v);
leaf.insert({(int)st[x].size(), x});
}
st[v] = stchange;
}
}
void cal(int u)
{
//cout << u <<" "<<d[u]<<" "<<a[d[u]]<<'\n';
for(int v: adj[u])
{
if(res.find(v) == res.end())continue;
a[d[v]] = Move(v);
res.erase(v);
cal(v);
Move(u);
}
}
ll Ioi(int n, int m, int A[], int B[], int P, int V, int T)
{
for(int i = 0; i < n; i ++)
{
st[i].clear();
adj[i].clear();
}
res.clear();
cur.clear();
leaf.clear();
cnt = 0;
ok = false;
for(int i = 0; i < m; i ++)
{
adj[A[i]].pb(B[i]);
adj[B[i]].pb(A[i]);
}
fill_n(d, n, -1);
fill_n(par, n, -1);
fill_n(vis, n, 0);
dfs(0, P);
fill_n(a, M, -1);
res.erase(P);
a[d[P]] = V;
cal(P);
ll res = 0;
for(int i = 0; i < M; i ++)
{
//cout << a[i] <<" "<<i<<'\n';
assert(a[i] != -1);
if(a[i])
res |= (1ll<<i);
}
return res;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
28940 KB |
Output is correct |
2 |
Correct |
16 ms |
28952 KB |
Output is correct |
3 |
Correct |
15 ms |
28964 KB |
Output is correct |
4 |
Correct |
14 ms |
28964 KB |
Output is correct |
5 |
Correct |
15 ms |
28968 KB |
Output is correct |
6 |
Correct |
15 ms |
28960 KB |
Output is correct |
7 |
Correct |
16 ms |
28960 KB |
Output is correct |
8 |
Correct |
15 ms |
28892 KB |
Output is correct |
9 |
Correct |
16 ms |
28964 KB |
Output is correct |
10 |
Correct |
16 ms |
28968 KB |
Output is correct |
11 |
Correct |
22 ms |
29180 KB |
Output is correct |
12 |
Correct |
14 ms |
28964 KB |
Output is correct |
13 |
Correct |
16 ms |
28992 KB |
Output is correct |
14 |
Correct |
16 ms |
28956 KB |
Output is correct |
15 |
Correct |
16 ms |
28896 KB |
Output is correct |
16 |
Correct |
16 ms |
28976 KB |
Output is correct |
17 |
Correct |
16 ms |
28964 KB |
Output is correct |
18 |
Correct |
15 ms |
28968 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
61 ms |
34088 KB |
Output is correct |
2 |
Correct |
69 ms |
34224 KB |
Output is correct |
3 |
Correct |
64 ms |
34096 KB |
Output is correct |
4 |
Correct |
52 ms |
30420 KB |
Output is correct |
5 |
Correct |
53 ms |
32628 KB |
Output is correct |
6 |
Correct |
49 ms |
32008 KB |
Output is correct |
7 |
Correct |
49 ms |
32100 KB |
Output is correct |
8 |
Correct |
54 ms |
32380 KB |
Output is correct |
9 |
Correct |
53 ms |
32476 KB |
Output is correct |
10 |
Correct |
45 ms |
30608 KB |
Output is correct |
11 |
Correct |
49 ms |
30488 KB |
Output is correct |
12 |
Correct |
43 ms |
30336 KB |
Output is correct |
13 |
Correct |
42 ms |
30352 KB |
Output is correct |
14 |
Correct |
46 ms |
30256 KB |
Output is correct |
15 |
Correct |
48 ms |
30388 KB |
Output is correct |
16 |
Correct |
50 ms |
30472 KB |
Output is correct |
17 |
Correct |
57 ms |
30416 KB |
Output is correct |
18 |
Correct |
55 ms |
30400 KB |
Output is correct |
19 |
Correct |
50 ms |
30536 KB |
Output is correct |
20 |
Correct |
44 ms |
32848 KB |
Output is correct |
21 |
Correct |
43 ms |
32872 KB |
Output is correct |
22 |
Correct |
51 ms |
31664 KB |
Output is correct |
23 |
Correct |
51 ms |
32460 KB |
Output is correct |
24 |
Correct |
52 ms |
32120 KB |
Output is correct |
25 |
Correct |
57 ms |
32200 KB |
Output is correct |
26 |
Correct |
54 ms |
32500 KB |
Output is correct |
27 |
Correct |
55 ms |
32512 KB |
Output is correct |
28 |
Correct |
52 ms |
32616 KB |
Output is correct |
29 |
Correct |
49 ms |
32176 KB |
Output is correct |
30 |
Correct |
66 ms |
32192 KB |
Output is correct |
31 |
Correct |
16 ms |
28972 KB |
Output is correct |
32 |
Correct |
16 ms |
28968 KB |
Output is correct |
33 |
Correct |
15 ms |
28960 KB |
Output is correct |
34 |
Correct |
14 ms |
28964 KB |
Output is correct |
35 |
Correct |
17 ms |
28956 KB |
Output is correct |
36 |
Correct |
15 ms |
28956 KB |
Output is correct |
37 |
Correct |
14 ms |
28972 KB |
Output is correct |
38 |
Correct |
15 ms |
28972 KB |
Output is correct |
39 |
Correct |
15 ms |
28972 KB |
Output is correct |
40 |
Correct |
17 ms |
29004 KB |
Output is correct |
41 |
Correct |
20 ms |
28964 KB |
Output is correct |
42 |
Correct |
15 ms |
28964 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
28968 KB |
Output is correct |
2 |
Correct |
15 ms |
28940 KB |
Output is correct |
3 |
Correct |
14 ms |
28876 KB |
Output is correct |
4 |
Correct |
20 ms |
30012 KB |
Output is correct |
5 |
Correct |
20 ms |
30028 KB |
Output is correct |
6 |
Correct |
20 ms |
30008 KB |
Output is correct |
7 |
Correct |
22 ms |
30000 KB |
Output is correct |
8 |
Correct |
24 ms |
30020 KB |
Output is correct |
9 |
Correct |
53 ms |
35248 KB |
Output is correct |
10 |
Correct |
46 ms |
35456 KB |
Output is correct |
11 |
Correct |
47 ms |
35384 KB |
Output is correct |
12 |
Correct |
14 ms |
28960 KB |
Output is correct |
13 |
Correct |
20 ms |
29040 KB |
Output is correct |
14 |
Correct |
15 ms |
28952 KB |
Output is correct |
15 |
Correct |
16 ms |
28968 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
66 ms |
34064 KB |
Output is correct |
2 |
Correct |
63 ms |
34040 KB |
Output is correct |
3 |
Correct |
64 ms |
34240 KB |
Output is correct |
4 |
Correct |
47 ms |
30424 KB |
Output is correct |
5 |
Correct |
56 ms |
33824 KB |
Output is correct |
6 |
Correct |
52 ms |
32468 KB |
Output is correct |
7 |
Correct |
52 ms |
32288 KB |
Output is correct |
8 |
Correct |
62 ms |
31388 KB |
Output is correct |
9 |
Correct |
54 ms |
31840 KB |
Output is correct |
10 |
Correct |
48 ms |
30560 KB |
Output is correct |
11 |
Correct |
44 ms |
30576 KB |
Output is correct |
12 |
Correct |
43 ms |
30376 KB |
Output is correct |
13 |
Correct |
43 ms |
30380 KB |
Output is correct |
14 |
Correct |
48 ms |
30408 KB |
Output is correct |
15 |
Correct |
49 ms |
30408 KB |
Output is correct |
16 |
Correct |
47 ms |
30516 KB |
Output is correct |
17 |
Correct |
46 ms |
30300 KB |
Output is correct |
18 |
Correct |
51 ms |
30728 KB |
Output is correct |
19 |
Correct |
52 ms |
30320 KB |
Output is correct |
20 |
Correct |
48 ms |
32880 KB |
Output is correct |
21 |
Correct |
45 ms |
32888 KB |
Output is correct |
22 |
Correct |
57 ms |
32276 KB |
Output is correct |
23 |
Correct |
52 ms |
32024 KB |
Output is correct |
24 |
Correct |
56 ms |
31976 KB |
Output is correct |
25 |
Correct |
56 ms |
32388 KB |
Output is correct |
26 |
Correct |
51 ms |
32344 KB |
Output is correct |
27 |
Correct |
52 ms |
32764 KB |
Output is correct |
28 |
Correct |
52 ms |
31876 KB |
Output is correct |
29 |
Correct |
49 ms |
31804 KB |
Output is correct |
30 |
Correct |
59 ms |
32396 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
71 ms |
34092 KB |
Output is correct |
2 |
Correct |
67 ms |
34392 KB |
Output is correct |
3 |
Correct |
63 ms |
34064 KB |
Output is correct |
4 |
Correct |
47 ms |
30480 KB |
Output is correct |
5 |
Correct |
51 ms |
34468 KB |
Output is correct |
6 |
Correct |
50 ms |
31800 KB |
Output is correct |
7 |
Correct |
57 ms |
31612 KB |
Output is correct |
8 |
Correct |
57 ms |
32328 KB |
Output is correct |
9 |
Correct |
51 ms |
32072 KB |
Output is correct |
10 |
Correct |
43 ms |
30584 KB |
Output is correct |
11 |
Correct |
41 ms |
30568 KB |
Output is correct |
12 |
Correct |
41 ms |
30328 KB |
Output is correct |
13 |
Correct |
41 ms |
30284 KB |
Output is correct |
14 |
Correct |
46 ms |
30356 KB |
Output is correct |
15 |
Correct |
54 ms |
30480 KB |
Output is correct |
16 |
Correct |
49 ms |
30552 KB |
Output is correct |
17 |
Correct |
49 ms |
30372 KB |
Output is correct |
18 |
Correct |
46 ms |
30524 KB |
Output is correct |
19 |
Correct |
47 ms |
30512 KB |
Output is correct |
20 |
Correct |
61 ms |
32956 KB |
Output is correct |
21 |
Correct |
46 ms |
32756 KB |
Output is correct |
22 |
Correct |
52 ms |
32264 KB |
Output is correct |
23 |
Correct |
50 ms |
31952 KB |
Output is correct |
24 |
Correct |
50 ms |
31832 KB |
Output is correct |
25 |
Correct |
51 ms |
32064 KB |
Output is correct |
26 |
Correct |
54 ms |
31824 KB |
Output is correct |
27 |
Correct |
52 ms |
32844 KB |
Output is correct |
28 |
Correct |
62 ms |
32788 KB |
Output is correct |
29 |
Correct |
54 ms |
32376 KB |
Output is correct |
30 |
Correct |
49 ms |
32236 KB |
Output is correct |
31 |
Correct |
16 ms |
28960 KB |
Output is correct |
32 |
Correct |
16 ms |
29096 KB |
Output is correct |
33 |
Correct |
14 ms |
29008 KB |
Output is correct |
34 |
Correct |
15 ms |
28960 KB |
Output is correct |
35 |
Correct |
14 ms |
29140 KB |
Output is correct |
36 |
Correct |
16 ms |
28960 KB |
Output is correct |
37 |
Correct |
14 ms |
28976 KB |
Output is correct |
38 |
Correct |
16 ms |
28960 KB |
Output is correct |
39 |
Correct |
17 ms |
28888 KB |
Output is correct |
40 |
Correct |
15 ms |
28940 KB |
Output is correct |
41 |
Correct |
14 ms |
28972 KB |
Output is correct |
42 |
Correct |
14 ms |
28860 KB |
Output is correct |