#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
typedef long long int LLI;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<pii> vpii;
#include "Joi.h"
static int parent[10000];
int find(int n) {
if (parent[n] != n) parent[n] = find(parent[n]);
return parent[n];
}
static vi adjList[10000];
static int key[10000],nxt[10000],heavy[100000];
static int visited[10000];
static queue<int> Q;
static int doDFS(int u,int p) {
int i;
int m = 1,mv = -1;
for (i = 0; i < adjList[u].size(); i++) {
int v = adjList[u][i];
if (v != p) {
int r = doDFS(v,u);
if (r+1 > m) m = r+1,mv = v;
}
}
nxt[u] = mv;
if (m == 60) {
key[u] = 1;
return 0;
}
else return m;
}
static int num = 0;
static int message[10000];
static int doDFS2(int u,int p,LLI X) {
int i;
if (num < 60) {
MessageBoard(u,((X & (1LL << num)) > 0));
message[u] = 1;
}
num++;
if (heavy[u] != -1) doDFS2(heavy[u],u,X);
for (i = 0; i < adjList[u].size(); i++) {
int v = adjList[u][i];
if ((v != p) && (v != heavy[u])) doDFS2(v,u,X);
}
return 0;
}
void Joi(int N,int M,int A[],int B[],long long int X,int T) {
int i;
for (i = 0; i < N; i++) parent[i] = i;
for (i = 0; i < M; i++) {
int pa = find(A[i]),pb = find(B[i]);
if (pa != pb) {
parent[pa] = pb;
adjList[A[i]].pb(B[i]);
adjList[B[i]].pb(A[i]);
}
}
int e = 0,e2 = 0;
Q.push(0);
while (!Q.empty()) {
int u = Q.front();
Q.pop();
e = u;
for (i = 0; i < adjList[u].size(); i++) {
int v = adjList[u][i];
if (!visited[v]) {
visited[v] = 1;
Q.push(v);
}
}
}
fill(parent,parent+N,-1);
fill(visited,visited+N,0);
Q.push(e);
while (!Q.empty()) {
int u = Q.front();
Q.pop();
e2 = u;
for (i = 0; i < adjList[u].size(); i++) {
int v = adjList[u][i];
if (!visited[v]) {
visited[v] = 1;
parent[v] = u;
Q.push(v);
}
}
}
fill(heavy,heavy+N,-1);
while (e2 != e) heavy[parent[e2]] = e2,e2 = parent[e2];
int j,f = 0;
doDFS(e,-1);
for (i = 0; i < N; i++) {
if (key[i]) {
int u = i;
for (j = 0; j < 60; j++) {
MessageBoard(u,((X & (1LL << j)) > 0));
message[u] = 1;
u = nxt[u];
}
f = 1;
}
}
if (!f) doDFS2(e,-1,X);
for (i = 0; i < N; i++) {
if (!message[i]) MessageBoard(i,0);
}
}
#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
typedef long long int LLI;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<pii> vpii;
#include "Ioi.h"
static int parent[10000];
static int find(int n) {
if (parent[n] != n) parent[n] = find(parent[n]);
return parent[n];
}
static vi adjList[10000];
static int key[10000],nxt[10000],heavy[10000];
static int visited[10000];
static queue<int> Q;
static int doDFS(int u,int p) {
int i;
int m = 1,mv = -1;
for (i = 0; i < adjList[u].size(); i++) {
int v = adjList[u][i];
if (v != p) {
int r = doDFS(v,u);
if (r+1 > m) m = r+1,mv = v;
}
}
nxt[u] = mv;
if (m == 60) {
key[u] = 1;
return 0;
}
else return m;
}
static int message[10000];
static int moveto(int s,int e,int N) {
int i,u;
fill(parent,parent+N,-1);
Q.push(s);
while (!Q.empty()) {
u = Q.front();
Q.pop();
if (key[u]) break;
for (i = 0; i < adjList[u].size(); i++) {
int v = adjList[u][i];
if ((v != s) && (parent[v] == -1)) {
parent[v] = u;
Q.push(v);
}
}
}
while (!Q.empty()) Q.pop();
vi path;
if (!key[u]) u = e;
while (u != -1) path.pb(u),u = parent[u];
for (i = (int) path.size()-2; i >= 0; i--) message[path[i]] = Move(path[i]);
return path[0];
}
static int num = 0;
static LLI ans = 0;
static int doDFS2(int u,int p) {
int i;
if (num < 60) {
if (message[u]) ans |= (1LL << num);
}
num++;
if (heavy[u] != -1) {
if (num < 60) {
message[heavy[u]] = Move(heavy[u]);
doDFS2(heavy[u],u);
if (num < 60) Move(u);
}
}
for (i = 0; i < adjList[u].size(); i++) {
int v = adjList[u][i];
if ((v != p) && (v != heavy[u])) {
if (num < 60) {
message[v] = Move(v);
doDFS2(v,u);
if (num < 60) Move(u);
}
}
}
return 0;
}
long long int Ioi(int N,int M,int A[],int B[],int P,int V,int T) {
int i;
for (i = 0; i < N; i++) parent[i] = i;
for (i = 0; i < M; i++) {
int pa = find(A[i]),pb = find(B[i]);
if (pa != pb) {
parent[pa] = pb;
adjList[A[i]].pb(B[i]);
adjList[B[i]].pb(A[i]);
}
}
int e = 0,e2 = 0;
Q.push(0);
while (!Q.empty()) {
int u = Q.front();
Q.pop();
e = u;
for (i = 0; i < adjList[u].size(); i++) {
int v = adjList[u][i];
if (!visited[v]) {
visited[v] = 1;
Q.push(v);
}
}
}
fill(parent,parent+N,-1);
fill(visited,visited+N,0);
Q.push(e);
while (!Q.empty()) {
int u = Q.front();
Q.pop();
e2 = u;
for (i = 0; i < adjList[u].size(); i++) {
int v = adjList[u][i];
if (!visited[v]) {
visited[v] = 1;
parent[v] = u;
Q.push(v);
}
}
}
fill(heavy,heavy+N,-1);
while (e2 != e) heavy[parent[e2]] = e2,e2 = parent[e2];
doDFS(e,-1);
fill(message,message+N,-1);
message[P] = V;
int d = moveto(P,e,N);
if (key[d]) {
LLI X = 0;
int u = d;
for (i = 0; i < 60; i++) {
if (message[u]) X |= (1LL << i);
u = nxt[u];
if (i < 59) message[u] = Move(u);
}
return X;
}
else {
doDFS2(e,-1);
return ans;
}
}
Compilation message
Joi.cpp: In function 'int doDFS(int, int)':
Joi.cpp:23:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (i = 0; i < adjList[u].size(); i++) {
~~^~~~~~~~~~~~~~~~~~~
Joi.cpp: In function 'int doDFS2(int, int, LLI)':
Joi.cpp:47:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (i = 0; i < adjList[u].size(); i++) {
~~^~~~~~~~~~~~~~~~~~~
Joi.cpp: In function 'void Joi(int, int, int*, int*, long long int, int)':
Joi.cpp:71:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (i = 0; i < adjList[u].size(); i++) {
~~^~~~~~~~~~~~~~~~~~~
Joi.cpp:87:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (i = 0; i < adjList[u].size(); i++) {
~~^~~~~~~~~~~~~~~~~~~
Ioi.cpp: In function 'int doDFS(int, int)':
Ioi.cpp:23:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (i = 0; i < adjList[u].size(); i++) {
~~^~~~~~~~~~~~~~~~~~~
Ioi.cpp: In function 'int moveto(int, int, int)':
Ioi.cpp:47:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (i = 0; i < adjList[u].size(); i++) {
~~^~~~~~~~~~~~~~~~~~~
Ioi.cpp: In function 'int doDFS2(int, int)':
Ioi.cpp:77:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (i = 0; i < adjList[u].size(); i++) {
~~^~~~~~~~~~~~~~~~~~~
Ioi.cpp: In function 'long long int Ioi(int, int, int*, int*, int, int, int)':
Ioi.cpp:107:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (i = 0; i < adjList[u].size(); i++) {
~~^~~~~~~~~~~~~~~~~~~
Ioi.cpp:123:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (i = 0; i < adjList[u].size(); i++) {
~~^~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
1248 KB |
Output is correct |
2 |
Correct |
8 ms |
1592 KB |
Output is correct |
3 |
Correct |
6 ms |
1772 KB |
Output is correct |
4 |
Correct |
6 ms |
1936 KB |
Output is correct |
5 |
Correct |
5 ms |
2056 KB |
Output is correct |
6 |
Correct |
6 ms |
2096 KB |
Output is correct |
7 |
Correct |
7 ms |
2136 KB |
Output is correct |
8 |
Correct |
5 ms |
2176 KB |
Output is correct |
9 |
Correct |
8 ms |
2176 KB |
Output is correct |
10 |
Correct |
6 ms |
2176 KB |
Output is correct |
11 |
Correct |
10 ms |
2240 KB |
Output is correct |
12 |
Correct |
6 ms |
2240 KB |
Output is correct |
13 |
Correct |
6 ms |
2240 KB |
Output is correct |
14 |
Correct |
6 ms |
2240 KB |
Output is correct |
15 |
Correct |
5 ms |
2240 KB |
Output is correct |
16 |
Correct |
6 ms |
2240 KB |
Output is correct |
17 |
Correct |
6 ms |
2240 KB |
Output is correct |
18 |
Correct |
5 ms |
2240 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
40 ms |
4552 KB |
Output is correct |
2 |
Correct |
36 ms |
4552 KB |
Output is correct |
3 |
Correct |
35 ms |
4552 KB |
Output is correct |
4 |
Correct |
27 ms |
4552 KB |
Output is correct |
5 |
Correct |
33 ms |
5280 KB |
Output is correct |
6 |
Correct |
27 ms |
5376 KB |
Output is correct |
7 |
Correct |
24 ms |
5376 KB |
Output is correct |
8 |
Correct |
28 ms |
5376 KB |
Output is correct |
9 |
Correct |
25 ms |
5376 KB |
Output is correct |
10 |
Correct |
27 ms |
5376 KB |
Output is correct |
11 |
Correct |
23 ms |
5376 KB |
Output is correct |
12 |
Correct |
20 ms |
5376 KB |
Output is correct |
13 |
Correct |
23 ms |
5376 KB |
Output is correct |
14 |
Correct |
23 ms |
5376 KB |
Output is correct |
15 |
Correct |
32 ms |
5376 KB |
Output is correct |
16 |
Correct |
25 ms |
5376 KB |
Output is correct |
17 |
Correct |
26 ms |
5376 KB |
Output is correct |
18 |
Correct |
25 ms |
5376 KB |
Output is correct |
19 |
Correct |
32 ms |
5376 KB |
Output is correct |
20 |
Correct |
23 ms |
5376 KB |
Output is correct |
21 |
Correct |
20 ms |
5376 KB |
Output is correct |
22 |
Correct |
27 ms |
5376 KB |
Output is correct |
23 |
Correct |
25 ms |
5376 KB |
Output is correct |
24 |
Correct |
27 ms |
5376 KB |
Output is correct |
25 |
Correct |
26 ms |
5376 KB |
Output is correct |
26 |
Correct |
27 ms |
5376 KB |
Output is correct |
27 |
Correct |
24 ms |
5376 KB |
Output is correct |
28 |
Correct |
23 ms |
5376 KB |
Output is correct |
29 |
Correct |
26 ms |
5376 KB |
Output is correct |
30 |
Correct |
23 ms |
5376 KB |
Output is correct |
31 |
Correct |
6 ms |
5376 KB |
Output is correct |
32 |
Correct |
6 ms |
5376 KB |
Output is correct |
33 |
Correct |
4 ms |
5376 KB |
Output is correct |
34 |
Correct |
6 ms |
5376 KB |
Output is correct |
35 |
Correct |
5 ms |
5376 KB |
Output is correct |
36 |
Correct |
5 ms |
5376 KB |
Output is correct |
37 |
Correct |
6 ms |
5376 KB |
Output is correct |
38 |
Correct |
7 ms |
5376 KB |
Output is correct |
39 |
Correct |
4 ms |
5376 KB |
Output is correct |
40 |
Correct |
5 ms |
5376 KB |
Output is correct |
41 |
Correct |
6 ms |
5376 KB |
Output is correct |
42 |
Correct |
5 ms |
5376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
5376 KB |
Output is correct |
2 |
Correct |
4 ms |
5376 KB |
Output is correct |
3 |
Correct |
4 ms |
5376 KB |
Output is correct |
4 |
Correct |
9 ms |
5376 KB |
Output is correct |
5 |
Correct |
8 ms |
5376 KB |
Output is correct |
6 |
Correct |
9 ms |
5376 KB |
Output is correct |
7 |
Correct |
7 ms |
5376 KB |
Output is correct |
8 |
Correct |
6 ms |
5376 KB |
Output is correct |
9 |
Correct |
23 ms |
5412 KB |
Output is correct |
10 |
Correct |
24 ms |
5576 KB |
Output is correct |
11 |
Correct |
18 ms |
5576 KB |
Output is correct |
12 |
Correct |
6 ms |
5576 KB |
Output is correct |
13 |
Correct |
6 ms |
5576 KB |
Output is correct |
14 |
Correct |
5 ms |
5576 KB |
Output is correct |
15 |
Correct |
5 ms |
5576 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
39 ms |
5576 KB |
Output is correct |
2 |
Correct |
37 ms |
5576 KB |
Output is correct |
3 |
Correct |
36 ms |
5576 KB |
Output is correct |
4 |
Correct |
26 ms |
5576 KB |
Output is correct |
5 |
Correct |
24 ms |
5576 KB |
Output is correct |
6 |
Correct |
26 ms |
5576 KB |
Output is correct |
7 |
Correct |
25 ms |
5576 KB |
Output is correct |
8 |
Correct |
28 ms |
5576 KB |
Output is correct |
9 |
Correct |
29 ms |
5576 KB |
Output is correct |
10 |
Correct |
24 ms |
5576 KB |
Output is correct |
11 |
Correct |
25 ms |
5576 KB |
Output is correct |
12 |
Correct |
22 ms |
5576 KB |
Output is correct |
13 |
Correct |
28 ms |
5576 KB |
Output is correct |
14 |
Correct |
35 ms |
5576 KB |
Output is correct |
15 |
Correct |
27 ms |
5576 KB |
Output is correct |
16 |
Correct |
26 ms |
5576 KB |
Output is correct |
17 |
Correct |
34 ms |
5576 KB |
Output is correct |
18 |
Correct |
31 ms |
5576 KB |
Output is correct |
19 |
Correct |
33 ms |
5576 KB |
Output is correct |
20 |
Correct |
19 ms |
5576 KB |
Output is correct |
21 |
Correct |
18 ms |
5576 KB |
Output is correct |
22 |
Correct |
26 ms |
5576 KB |
Output is correct |
23 |
Correct |
28 ms |
5576 KB |
Output is correct |
24 |
Correct |
30 ms |
5576 KB |
Output is correct |
25 |
Correct |
23 ms |
5576 KB |
Output is correct |
26 |
Correct |
26 ms |
5576 KB |
Output is correct |
27 |
Correct |
24 ms |
5576 KB |
Output is correct |
28 |
Correct |
25 ms |
5576 KB |
Output is correct |
29 |
Correct |
24 ms |
5576 KB |
Output is correct |
30 |
Correct |
25 ms |
5576 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
36 ms |
5576 KB |
Output is correct |
2 |
Correct |
45 ms |
5576 KB |
Output is correct |
3 |
Correct |
41 ms |
5576 KB |
Output is correct |
4 |
Correct |
27 ms |
5576 KB |
Output is correct |
5 |
Correct |
32 ms |
5576 KB |
Output is correct |
6 |
Correct |
34 ms |
5576 KB |
Output is correct |
7 |
Correct |
27 ms |
5576 KB |
Output is correct |
8 |
Correct |
26 ms |
5576 KB |
Output is correct |
9 |
Correct |
27 ms |
5576 KB |
Output is correct |
10 |
Correct |
24 ms |
5576 KB |
Output is correct |
11 |
Correct |
19 ms |
5576 KB |
Output is correct |
12 |
Correct |
23 ms |
5576 KB |
Output is correct |
13 |
Correct |
20 ms |
5576 KB |
Output is correct |
14 |
Correct |
25 ms |
5576 KB |
Output is correct |
15 |
Correct |
26 ms |
5576 KB |
Output is correct |
16 |
Correct |
23 ms |
5576 KB |
Output is correct |
17 |
Correct |
31 ms |
5576 KB |
Output is correct |
18 |
Correct |
26 ms |
5576 KB |
Output is correct |
19 |
Correct |
26 ms |
5576 KB |
Output is correct |
20 |
Correct |
22 ms |
6104 KB |
Output is correct |
21 |
Correct |
19 ms |
6112 KB |
Output is correct |
22 |
Correct |
28 ms |
6372 KB |
Output is correct |
23 |
Correct |
31 ms |
6712 KB |
Output is correct |
24 |
Correct |
27 ms |
6872 KB |
Output is correct |
25 |
Correct |
27 ms |
7092 KB |
Output is correct |
26 |
Correct |
24 ms |
7264 KB |
Output is correct |
27 |
Correct |
31 ms |
7264 KB |
Output is correct |
28 |
Correct |
26 ms |
7648 KB |
Output is correct |
29 |
Correct |
27 ms |
7648 KB |
Output is correct |
30 |
Correct |
27 ms |
7780 KB |
Output is correct |
31 |
Correct |
6 ms |
7800 KB |
Output is correct |
32 |
Correct |
5 ms |
7800 KB |
Output is correct |
33 |
Correct |
5 ms |
7800 KB |
Output is correct |
34 |
Correct |
5 ms |
7800 KB |
Output is correct |
35 |
Correct |
5 ms |
7800 KB |
Output is correct |
36 |
Correct |
6 ms |
7800 KB |
Output is correct |
37 |
Correct |
4 ms |
7800 KB |
Output is correct |
38 |
Incorrect |
4 ms |
7800 KB |
Output isn't correct |
39 |
Halted |
0 ms |
0 KB |
- |