#include <stdio.h>
#include "Joi.h"
#include <vector>
#include <set>
#define SZ 60
static std::vector<int> AdjList[10005];
static std::set<int> Set[10005];
static int Vis[10005];
static int Role[10005];
// static int HELLO = 0;
static void FirstSet(int u, int pa)
{
// printf("FirstSet u%d pa%d s%d\n", u, pa, AdjList[u].size());
if (Set[0].size() < SZ)
{
Role[u] = Set[0].size();
Set[0].insert(u);
}
int i, j, v;
Vis[u] = 1;
for (i = 0; i < AdjList[u].size(); i++)
{
v = AdjList[u][i];
// printf(".");
if (v != pa)
{
// printf(".");
if (!Vis[v])
{
// HELLO++;
FirstSet(v, u);
// HELLO--;
}
else
{
AdjList[u].erase(AdjList[u].begin() + i);
for (j = 0; j < AdjList[v].size(); j++)
if (AdjList[v][j] == u)
break;
if (j < AdjList[v].size())
AdjList[v].erase(AdjList[v].begin() + j);
else
printf("WTF\n");
i--;
}
}
}
}
// static int HELLO;
static void OtherSet(int u, int pa)
{
// printf("OtherSet u%d pa%d\n", u, pa);
// HELLO++;
int i, j, v, s, d;
if (u != 0)
{
Set[u] = Set[pa];
if (Set[u].find(u) == Set[u].end())
{
std::set<int>::iterator it;
Set[u].insert(u);
// for (it = Set[u].begin(); it != Set[u].end(); it++)
// printf("%d ", *it);
// printf("\n");
for (it = Set[u].begin(); it != Set[u].end(); it++)
{
if (*it == pa || *it == u)
continue;
s = AdjList[*it].size();
d = 0;
for (j = 0; j < s; j++)
{
if (Set[u].find(AdjList[*it][j]) != Set[u].end())
{
// printf("%d-%d\n", *it, AdjList[*it][j]);
d++;
}
// else
// printf("%d-%dX\n", *it, AdjList[*it][j]);
}
if (d == 1)
break;
}
if (it != Set[u].end())
{
Role[u] = Role[*it];
Set[u].erase(it);
// printf("u %d pa %d erase %d d %d\n", u, pa, *it, d);
}
}
}
s = AdjList[u].size();
for (i = 0; i < s; i++)
{
v = AdjList[u][i];
if (v != pa && Set[v].size() == 0)
{
OtherSet(v, u);
}
}
}
void Joi(int N, int M, int A[], int B[], long long X, int T)
{
int i;
for (i = 0; i < M; i++)
{
AdjList[A[i]].push_back(B[i]);
AdjList[B[i]].push_back(A[i]);
}
FirstSet(0, -1);
// printf("FirstSet fin\n");
// for (i = 0; i < N; i++)
// HELLO += AdjList[i].size();
// printf("HELLO %d\n", HELLO);
OtherSet(0, -1);
// printf("OtherSet fin %d\n", HELLO);
int val[SZ];
for (i = 0; i < SZ; i++)
{
val[i] = X%2;
X >>= 1;
}
for (i = 0; i < N; i++)
{
MessageBoard(i, val[Role[i]]);
}
// printf("Joi fin\n");
}
#include <stdio.h>
#include "Ioi.h"
#include <vector>
#include <set>
#define SZ 60
static std::vector<int> AdjList[10005];
static std::set<int> Set[10005];
static int Vis[10005];
static int Role[10005];
static void FirstSet(int u, int pa)
{
// printf("FirstSet u%d pa%d s%d\n", u, pa, AdjList[u].size());
if (Set[0].size() < SZ)
{
Role[u] = Set[0].size();
Set[0].insert(u);
}
int i, j, v;
Vis[u] = 1;
for (i = 0; i < AdjList[u].size(); i++)
{
v = AdjList[u][i];
// printf(".");
if (v != pa)
{
// printf(".");
if (!Vis[v])
{
// HELLO++;
FirstSet(v, u);
// HELLO--;
}
else
{
AdjList[u].erase(AdjList[u].begin() + i);
for (j = 0; j < AdjList[v].size(); j++)
if (AdjList[v][j] == u)
break;
if (j < AdjList[v].size())
AdjList[v].erase(AdjList[v].begin() + j);
else
printf("WTF\n");
i--;
}
}
}
}
// static int HELLO;
static void OtherSet(int u, int pa)
{
// printf("OtherSet u%d\n", u);
// HELLO++;
int i, j, v, s, d;
if (u != 0)
{
Set[u] = Set[pa];
if (Set[u].find(u) == Set[u].end())
{
std::set<int>::iterator it;
Set[u].insert(u);
for (it = Set[u].begin(); it != Set[u].end(); it++)
{
if (*it == pa || *it == u)
continue;
s = AdjList[*it].size();
d = 0;
for (j = 0; j < s; j++)
{
if (Set[u].find(AdjList[*it][j]) != Set[u].end())
d++;
}
if (d == 1)
break;
}
if (it != Set[u].end())
{
Role[u] = Role[*it];
Set[u].erase(it);
}
}
}
s = AdjList[u].size();
for (i = 0; i < s; i++)
{
v = AdjList[u][i];
if (v != pa && Set[v].size() == 0)
{
OtherSet(v, u);
}
}
}
static int val[SZ];
// static int HELLO;
void GetVal(int P, int u, int pa)
{
// printf("GetVal %d %d\n", u, pa);
// HELLO++;
int i, v, s = AdjList[u].size();
Vis[u] = 1;
for (i = 0; i < s; i++)
{
v = AdjList[u][i];
if (v != pa && !Vis[v] && Set[P].find(v) != Set[P].end())
{
val[Role[v]] = Move(v);
GetVal(P, v, u);
Move(u);
}
}
}
long long Ioi(int N, int M, int A[], int B[], int P, int V, int T)
{
int i;
for (i = 0; i < M; i++)
{
AdjList[A[i]].push_back(B[i]);
AdjList[B[i]].push_back(A[i]);
}
FirstSet(0, -1);
OtherSet(0, -1);
val[Role[P]] = V;
for (i = 0; i < N; i++)
Vis[i] = 0;
std::set<int>::iterator it;
// for (i = 0; i < N; i++)
// printf("%d\n", Set[i].size());
GetVal(P, P, -1);
// printf("GetVal fin %d %d\n", Set[P].size(), HELLO);
long long X = 0;
for (i = SZ - 1; i >= 0; i--)
{
X <<= 1;
X += val[i];
}
// printf("X %lld\n", X);
return X;
}
Compilation message
Joi.cpp: In function 'void FirstSet(int, int)':
Joi.cpp:21:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (i = 0; i < AdjList[u].size(); i++)
^
Joi.cpp:37:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (j = 0; j < AdjList[v].size(); j++)
^
Joi.cpp:40:11: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if (j < AdjList[v].size())
^
Ioi.cpp: In function 'void FirstSet(int, int)':
Ioi.cpp:20:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (i = 0; i < AdjList[u].size(); i++)
^
Ioi.cpp:36:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (j = 0; j < AdjList[v].size(); j++)
^
Ioi.cpp:39:11: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if (j < AdjList[v].size())
^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
5156 KB |
Output is correct |
2 |
Correct |
0 ms |
5420 KB |
Output is correct |
3 |
Correct |
0 ms |
6476 KB |
Output is correct |
4 |
Correct |
0 ms |
5156 KB |
Output is correct |
5 |
Correct |
0 ms |
5156 KB |
Output is correct |
6 |
Correct |
0 ms |
5684 KB |
Output is correct |
7 |
Correct |
0 ms |
6476 KB |
Output is correct |
8 |
Correct |
0 ms |
6212 KB |
Output is correct |
9 |
Correct |
0 ms |
6212 KB |
Output is correct |
10 |
Correct |
0 ms |
5420 KB |
Output is correct |
11 |
Correct |
3 ms |
5420 KB |
Output is correct |
12 |
Correct |
0 ms |
4892 KB |
Output is correct |
13 |
Correct |
0 ms |
6476 KB |
Output is correct |
14 |
Correct |
0 ms |
6476 KB |
Output is correct |
15 |
Correct |
0 ms |
6476 KB |
Output is correct |
16 |
Correct |
0 ms |
6212 KB |
Output is correct |
17 |
Correct |
0 ms |
6212 KB |
Output is correct |
18 |
Correct |
0 ms |
6212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
185 ms |
62680 KB |
Output is correct |
2 |
Correct |
179 ms |
62712 KB |
Output is correct |
3 |
Correct |
222 ms |
62704 KB |
Output is correct |
4 |
Correct |
139 ms |
61652 KB |
Output is correct |
5 |
Correct |
189 ms |
62404 KB |
Output is correct |
6 |
Correct |
202 ms |
62084 KB |
Output is correct |
7 |
Correct |
198 ms |
62112 KB |
Output is correct |
8 |
Correct |
199 ms |
62256 KB |
Output is correct |
9 |
Correct |
198 ms |
62280 KB |
Output is correct |
10 |
Correct |
161 ms |
61780 KB |
Output is correct |
11 |
Correct |
176 ms |
61780 KB |
Output is correct |
12 |
Correct |
156 ms |
56372 KB |
Output is correct |
13 |
Correct |
129 ms |
56372 KB |
Output is correct |
14 |
Correct |
152 ms |
59012 KB |
Output is correct |
15 |
Correct |
402 ms |
61388 KB |
Output is correct |
16 |
Correct |
178 ms |
61388 KB |
Output is correct |
17 |
Correct |
139 ms |
61652 KB |
Output is correct |
18 |
Correct |
176 ms |
61652 KB |
Output is correct |
19 |
Correct |
149 ms |
61652 KB |
Output is correct |
20 |
Correct |
99 ms |
62496 KB |
Output is correct |
21 |
Correct |
111 ms |
61424 KB |
Output is correct |
22 |
Correct |
212 ms |
61956 KB |
Output is correct |
23 |
Correct |
215 ms |
62256 KB |
Output is correct |
24 |
Correct |
222 ms |
62048 KB |
Output is correct |
25 |
Correct |
228 ms |
62164 KB |
Output is correct |
26 |
Correct |
219 ms |
62280 KB |
Output is correct |
27 |
Correct |
232 ms |
62276 KB |
Output is correct |
28 |
Correct |
212 ms |
62328 KB |
Output is correct |
29 |
Correct |
206 ms |
56868 KB |
Output is correct |
30 |
Correct |
189 ms |
59244 KB |
Output is correct |
31 |
Correct |
0 ms |
5420 KB |
Output is correct |
32 |
Correct |
0 ms |
5684 KB |
Output is correct |
33 |
Correct |
3 ms |
6212 KB |
Output is correct |
34 |
Correct |
0 ms |
5420 KB |
Output is correct |
35 |
Correct |
0 ms |
5156 KB |
Output is correct |
36 |
Correct |
0 ms |
5156 KB |
Output is correct |
37 |
Correct |
0 ms |
5156 KB |
Output is correct |
38 |
Correct |
0 ms |
4892 KB |
Output is correct |
39 |
Correct |
0 ms |
4892 KB |
Output is correct |
40 |
Correct |
0 ms |
5156 KB |
Output is correct |
41 |
Correct |
0 ms |
5156 KB |
Output is correct |
42 |
Correct |
0 ms |
5156 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
5156 KB |
Output is correct |
2 |
Correct |
0 ms |
5156 KB |
Output is correct |
3 |
Correct |
0 ms |
5156 KB |
Output is correct |
4 |
Correct |
9 ms |
13976 KB |
Output is correct |
5 |
Correct |
15 ms |
13972 KB |
Output is correct |
6 |
Correct |
9 ms |
13968 KB |
Output is correct |
7 |
Correct |
12 ms |
13976 KB |
Output is correct |
8 |
Correct |
15 ms |
13968 KB |
Output is correct |
9 |
Correct |
98 ms |
62772 KB |
Output is correct |
10 |
Correct |
112 ms |
62776 KB |
Output is correct |
11 |
Correct |
112 ms |
62768 KB |
Output is correct |
12 |
Correct |
0 ms |
5156 KB |
Output is correct |
13 |
Correct |
0 ms |
5156 KB |
Output is correct |
14 |
Correct |
0 ms |
4892 KB |
Output is correct |
15 |
Correct |
0 ms |
4892 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
245 ms |
62696 KB |
Output is correct |
2 |
Correct |
227 ms |
62708 KB |
Output is correct |
3 |
Correct |
231 ms |
62700 KB |
Output is correct |
4 |
Correct |
158 ms |
61652 KB |
Output is correct |
5 |
Correct |
202 ms |
62964 KB |
Output is correct |
6 |
Correct |
212 ms |
62284 KB |
Output is correct |
7 |
Correct |
198 ms |
62240 KB |
Output is correct |
8 |
Correct |
185 ms |
61852 KB |
Output is correct |
9 |
Correct |
219 ms |
62012 KB |
Output is correct |
10 |
Correct |
168 ms |
61780 KB |
Output is correct |
11 |
Correct |
179 ms |
61780 KB |
Output is correct |
12 |
Correct |
122 ms |
56372 KB |
Output is correct |
13 |
Correct |
149 ms |
56372 KB |
Output is correct |
14 |
Correct |
132 ms |
59012 KB |
Output is correct |
15 |
Correct |
139 ms |
61388 KB |
Output is correct |
16 |
Correct |
156 ms |
61388 KB |
Output is correct |
17 |
Correct |
162 ms |
61652 KB |
Output is correct |
18 |
Correct |
146 ms |
61652 KB |
Output is correct |
19 |
Correct |
202 ms |
61652 KB |
Output is correct |
20 |
Correct |
102 ms |
62496 KB |
Output is correct |
21 |
Correct |
115 ms |
61428 KB |
Output is correct |
22 |
Correct |
239 ms |
62216 KB |
Output is correct |
23 |
Correct |
222 ms |
62124 KB |
Output is correct |
24 |
Correct |
212 ms |
62108 KB |
Output is correct |
25 |
Correct |
231 ms |
62280 KB |
Output is correct |
26 |
Correct |
209 ms |
62224 KB |
Output is correct |
27 |
Correct |
205 ms |
62408 KB |
Output is correct |
28 |
Correct |
196 ms |
62008 KB |
Output is correct |
29 |
Correct |
231 ms |
56828 KB |
Output is correct |
30 |
Correct |
186 ms |
59296 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
208 ms |
62704 KB |
Output is correct |
2 |
Correct |
249 ms |
62716 KB |
Output is correct |
3 |
Correct |
239 ms |
62696 KB |
Output is correct |
4 |
Correct |
182 ms |
61652 KB |
Output is correct |
5 |
Correct |
202 ms |
63208 KB |
Output is correct |
6 |
Correct |
212 ms |
62028 KB |
Output is correct |
7 |
Correct |
205 ms |
61972 KB |
Output is correct |
8 |
Correct |
161 ms |
62268 KB |
Output is correct |
9 |
Correct |
186 ms |
62144 KB |
Output is correct |
10 |
Correct |
205 ms |
61780 KB |
Output is correct |
11 |
Correct |
179 ms |
61780 KB |
Output is correct |
12 |
Correct |
129 ms |
56372 KB |
Output is correct |
13 |
Correct |
188 ms |
56372 KB |
Output is correct |
14 |
Correct |
158 ms |
59012 KB |
Output is correct |
15 |
Correct |
138 ms |
61388 KB |
Output is correct |
16 |
Correct |
449 ms |
61388 KB |
Output is correct |
17 |
Correct |
142 ms |
61652 KB |
Output is correct |
18 |
Correct |
172 ms |
61652 KB |
Output is correct |
19 |
Correct |
185 ms |
61652 KB |
Output is correct |
20 |
Correct |
89 ms |
62500 KB |
Output is correct |
21 |
Correct |
89 ms |
61424 KB |
Output is correct |
22 |
Correct |
216 ms |
62172 KB |
Output is correct |
23 |
Correct |
198 ms |
62076 KB |
Output is correct |
24 |
Correct |
216 ms |
62088 KB |
Output is correct |
25 |
Correct |
202 ms |
62128 KB |
Output is correct |
26 |
Correct |
205 ms |
61964 KB |
Output is correct |
27 |
Correct |
196 ms |
62424 KB |
Output is correct |
28 |
Correct |
238 ms |
62448 KB |
Output is correct |
29 |
Correct |
215 ms |
57068 KB |
Output is correct |
30 |
Correct |
178 ms |
59368 KB |
Output is correct |
31 |
Correct |
0 ms |
5420 KB |
Output is correct |
32 |
Correct |
0 ms |
5684 KB |
Output is correct |
33 |
Correct |
0 ms |
6212 KB |
Output is correct |
34 |
Correct |
0 ms |
5420 KB |
Output is correct |
35 |
Correct |
0 ms |
5156 KB |
Output is correct |
36 |
Correct |
0 ms |
5156 KB |
Output is correct |
37 |
Correct |
0 ms |
5156 KB |
Output is correct |
38 |
Correct |
0 ms |
4892 KB |
Output is correct |
39 |
Correct |
0 ms |
4892 KB |
Output is correct |
40 |
Correct |
0 ms |
5156 KB |
Output is correct |
41 |
Correct |
0 ms |
5156 KB |
Output is correct |
42 |
Correct |
0 ms |
5156 KB |
Output is correct |