#include "Joi.h"
#include <bits/stdc++.h>
using namespace std;
template<class T, class U>
void ckmin(T &a, U b)
{
if (a > b) a = b;
}
template<class T, class U>
void ckmax(T &a, U b)
{
if (a < b) a = b;
}
#define MP make_pair
#define PB push_back
#define LB lower_bound
#define UB upper_bound
#define fi first
#define se second
#define SZ(x) ((int) (x).size())
#define ALL(x) (x).begin(), (x).end()
#define FOR(i, a, b) for (auto i = (a); i < (b); i++)
#define FORD(i, a, b) for (auto i = (a) - 1; i >= (b); i--)
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vpi;
typedef vector<pll> vpl;
static const int MAXN = 10013;
static int N, R, V = -1;
static bool islong;
static vi edge[MAXN];
static int dsu[MAXN];
static int depth[MAXN], parent[MAXN];
static vi ord;
static int get(int u)
{
return (u == dsu[u] ? u : dsu[u] = get(dsu[u]));
}
static bool merge(int u, int v)
{
u = get(u);
v = get(v);
if (u == v)
{
return false;
}
dsu[u] = v;
return true;
}
static void dfs(int u, int p)
{
for (int v : edge[u])
{
if (v == p) continue;
depth[v] = depth[u] + 1;
parent[v] = u;
dfs(v, u);
}
}
static void dfs1(int u, int p)
{
ord.PB(u);
for (int v : edge[u])
{
if (v == p) continue;
dfs1(v, u);
}
}
void Joi(int n, int m, int e1[], int e2[], ll val, int subtask)
{
N = n;
iota(dsu, dsu + N, 0);
FOR(i, 0, m)
{
int u = e1[i], v = e2[i];
if (merge(u, v))
{
edge[u].PB(v);
edge[v].PB(u);
// cerr << "edge " << u << ' ' << v << endl;
}
}
// cerr << "ALIVE\n";
depth[0] = 0;
dfs(0, N);
FOR(i, 0, N)
{
if (depth[i] > depth[R])
{
R = i;
}
}
depth[R] = 0;
dfs(R, N);
FOR(i, 0, N)
{
if (depth[i] == 59)
{
V = i;
}
}
if (V != -1)
{
//solve it...
FOR(i, 0, N)
{
bool b = (val & (1ll << (depth[i] % 60)));
MessageBoard(i, b);
}
}
else
{
dfs1(R, N);
FOR(i, 0, N)
{
bool b = (val & (1ll << (i % 60)));
MessageBoard(ord[i], b);
}
}
}
#include "Ioi.h"
#include <bits/stdc++.h>
using namespace std;
template<class T, class U>
void ckmin(T &a, U b)
{
if (a > b) a = b;
}
template<class T, class U>
void ckmax(T &a, U b)
{
if (a < b) a = b;
}
#define MP make_pair
#define PB push_back
#define LB lower_bound
#define UB upper_bound
#define fi first
#define se second
#define SZ(x) ((int) (x).size())
#define ALL(x) (x).begin(), (x).end()
#define FOR(i, a, b) for (auto i = (a); i < (b); i++)
#define FORD(i, a, b) for (auto i = (a) - 1; i >= (b); i--)
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vpi;
typedef vector<pll> vpl;
static const int MAXN = 10013;
static int N, R, V;
static vi edge[MAXN];
static int dsu[MAXN];
static int depth[MAXN], parent[MAXN], pos[MAXN];
static ll ans;
static vi ord;
static ll solved = 0;
static int get(int u)
{
return (u == dsu[u] ? u : dsu[u] = get(dsu[u]));
}
static bool merge(int u, int v)
{
u = get(u);
v = get(v);
if (u == v)
{
return false;
}
dsu[u] = v;
return true;
}
//fidn the diameter o the tree. if it's >= 60, gg.
//otherwise, go to the root, and then just like take the first 60 in preorder.
static void dfs(int u, int p)
{
for (int v : edge[u])
{
if (v == p) continue;
depth[v] = depth[u] + 1;
parent[v] = u;
dfs(v, u);
}
}
static void dfs1(int u, int p)
{
pos[u] = SZ(ord);
ord.PB(u);
for (int v : edge[u])
{
if (v == p) continue;
dfs1(v, u);
}
}
static void dfs2(int u, int p)
{
for (int v : edge[u])
{
if (v == p) continue;
// cerr << "Move " << v << endl;
int va = Move(v);
if (va)
{
ans |= (1ll << (pos[v] % 60));
}
solved |= (1ll << (pos[v] % 60));
if (solved == (1ll << 60) - 1)
{
return;
}
dfs2(v, u);
if (solved == (1ll << 60) - 1)
{
return;
}
// cerr << "Move " << v << " -> " << u << endl;
Move(u);
}
}
ll Ioi(int n, int m, int e1[], int e2[], int st, int va, int subtask)
{
N = n;
iota(dsu, dsu + N, 0);
FOR(i, 0, m)
{
int u = e1[i], v = e2[i];
if (merge(u, v))
{
edge[u].PB(v);
edge[v].PB(u);
// cerr << "edge " << u << ' ' << v << endl;
}
}
depth[0] = 0;
dfs(0, N);
FOR(i, 0, N)
{
if (depth[i] > depth[R])
{
R = i;
}
}
depth[R] = 0;
dfs(R, N);
FOR(i, 0, N)
{
if (depth[i] == 59)
{
V = i;
}
}
// cerr << "R = " << R << " V = " << V << endl;
if (V != -1)
{
vi path; path.PB(V);
while(path.back() != R)
{
path.PB(parent[path.back()]);
}
reverse(ALL(path));
if (depth[st] >= 59)
{
if (va)
{
ans += (1ll << (depth[st] % 60));
}
FOR(i, 0, 59)
{
va = Move(parent[st]);
st = parent[st];
if (va)
{
ans += (1ll << (depth[st] % 60));
}
}
}
else
{
while(st != R)
{
va = Move(parent[st]);
st = parent[st];
}
if (va)
{
ans += (1ll << (depth[st] % 60));
}
FOR(i, 1, 60)
{
va = Move(path[i]);
st = path[i];
if (va)
{
ans += (1ll << (depth[st] % 60));
}
}
}
}
else
{
dfs1(R, N);
if (va)
{
ans |= (1ll << (pos[st] % 60));
}
solved |= (1ll << (pos[st] % 60));
// cerr << "st = " << st << endl;
while(st != R)
{
va = Move(parent[st]);
// cerr << "Move " << parent[st] << endl;
st = parent[st];
if (va)
{
ans |= (1ll << (pos[st] % 60));
}
solved |= (1ll << (pos[st] % 60));
}
dfs2(R, N);
}
return ans;
}
Compilation message
Joi.cpp:41:13: warning: 'islong' defined but not used [-Wunused-variable]
static bool islong;
^~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
10 ms |
1516 KB |
Wrong Answer [7] |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
36 ms |
3720 KB |
Output is correct |
2 |
Correct |
38 ms |
3428 KB |
Output is correct |
3 |
Correct |
39 ms |
3628 KB |
Output is correct |
4 |
Incorrect |
26 ms |
3268 KB |
Wrong Answer [7] |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
1384 KB |
Output is correct |
2 |
Correct |
10 ms |
1408 KB |
Output is correct |
3 |
Correct |
10 ms |
1528 KB |
Output is correct |
4 |
Correct |
11 ms |
1756 KB |
Output is correct |
5 |
Correct |
11 ms |
1752 KB |
Output is correct |
6 |
Correct |
12 ms |
1764 KB |
Output is correct |
7 |
Correct |
13 ms |
1756 KB |
Output is correct |
8 |
Correct |
11 ms |
1748 KB |
Output is correct |
9 |
Correct |
24 ms |
3948 KB |
Output is correct |
10 |
Correct |
22 ms |
3796 KB |
Output is correct |
11 |
Correct |
20 ms |
3848 KB |
Output is correct |
12 |
Correct |
10 ms |
1412 KB |
Output is correct |
13 |
Correct |
10 ms |
1536 KB |
Output is correct |
14 |
Correct |
10 ms |
1532 KB |
Output is correct |
15 |
Correct |
10 ms |
1316 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
36 ms |
3568 KB |
Output is correct |
2 |
Correct |
35 ms |
3632 KB |
Output is correct |
3 |
Correct |
41 ms |
3628 KB |
Output is correct |
4 |
Incorrect |
25 ms |
3020 KB |
Wrong Answer [7] |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
36 ms |
3428 KB |
Output is correct |
2 |
Correct |
36 ms |
3556 KB |
Output is correct |
3 |
Correct |
36 ms |
3636 KB |
Output is correct |
4 |
Incorrect |
26 ms |
3260 KB |
Wrong Answer [7] |
5 |
Halted |
0 ms |
0 KB |
- |