#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;
^~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
10 ms |
1284 KB |
Wrong Answer [7] |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
37 ms |
3476 KB |
Output is correct |
2 |
Correct |
39 ms |
3484 KB |
Output is correct |
3 |
Correct |
36 ms |
3644 KB |
Output is correct |
4 |
Incorrect |
27 ms |
3328 KB |
Wrong Answer [7] |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
1532 KB |
Output is correct |
2 |
Correct |
10 ms |
1512 KB |
Output is correct |
3 |
Correct |
10 ms |
1544 KB |
Output is correct |
4 |
Correct |
12 ms |
1732 KB |
Output is correct |
5 |
Correct |
11 ms |
1764 KB |
Output is correct |
6 |
Correct |
12 ms |
1700 KB |
Output is correct |
7 |
Correct |
12 ms |
1764 KB |
Output is correct |
8 |
Correct |
12 ms |
1700 KB |
Output is correct |
9 |
Correct |
20 ms |
3796 KB |
Output is correct |
10 |
Correct |
23 ms |
3972 KB |
Output is correct |
11 |
Correct |
22 ms |
3840 KB |
Output is correct |
12 |
Correct |
10 ms |
1284 KB |
Output is correct |
13 |
Correct |
10 ms |
1660 KB |
Output is correct |
14 |
Correct |
10 ms |
1284 KB |
Output is correct |
15 |
Correct |
10 ms |
1444 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
35 ms |
3632 KB |
Output is correct |
2 |
Correct |
35 ms |
3624 KB |
Output is correct |
3 |
Correct |
36 ms |
3664 KB |
Output is correct |
4 |
Incorrect |
27 ms |
3028 KB |
Wrong Answer [7] |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
39 ms |
3628 KB |
Output is correct |
2 |
Correct |
37 ms |
3488 KB |
Output is correct |
3 |
Correct |
35 ms |
3648 KB |
Output is correct |
4 |
Incorrect |
27 ms |
2892 KB |
Wrong Answer [7] |
5 |
Halted |
0 ms |
0 KB |
- |