#include <bits/stdc++.h>
using namespace std;
#include "Joi.h"
void MessageBoard(int attr, int msg)
{
cout << "Pe panoul " << attr << " se scrie " << msg << '\n';
}
int Move(int desc)
{
cout << "Ma duc in " << desc << '\n';
int x;
cout << "Care este nr de acolo ??\n";
cin >> x;
return x;
}
namespace UF {
int tata[100010];
int g[100010];
int find(int x) {
if (tata[tata[x]] != tata[x])
tata[x] = find(tata[x]);
return tata[x];
}
bool unite(int a, int b) {
a = find(a);
b = find(b);
if (a == b)
return false;
if (g[a] > g[b])
g[a] += g[b], tata[b] = a;
else
g[b] += g[a], tata[a] = b;
return true;
}
void init() {
for (int i(0); i <= 100000; i++)
tata[i] = i, g[i] = 1;
}
}
int col[100010], colact;
vector <int> adia[100010];
int poz_in_adia[100010];
int fii[100010];
int tata[100010];
int nrcol = 7;
int biti[64];
int unknown;
bool tells;
int viz[100010];
void mk_cols(int nod)
{
if (tata[nod])
adia[nod].erase(find(adia[nod].begin(), adia[nod].end(), tata[nod]));
col[nod] = colact;
colact = (colact + 1) % nrcol;
if (tells)
MessageBoard(nod, biti[col[nod]]);
for (int i(0); i < adia[nod].size(); i++) {
poz_in_adia[adia[nod][i]] = i;
tata[adia[nod][i]] = nod;
mk_cols(adia[nod][i]);
}
}
void proc_input(int n, int m, int * a, int * b, long long x)
{
UF::init();
for (int i(0); i < m; i++) {
if (UF::unite(a[i], b[i])) {
adia[a[i]].push_back(b[i]);
adia[b[i]].push_back(a[i]);
}
}
if (x != -1) {
for (int i(0); i < nrcol; i++) {
biti[i] = x & 1ll;
x >>= 1;
}
}
else {
unknown = nrcol;
for (int i(0); i < nrcol; i++)
biti[i] = -1;
}
mk_cols(1);
}
void add_bit(int col, int bit)
{
if (biti[col] == -1)
unknown--;
biti[col] = bit;
}
void dfs(int nod, int i, int c)
{
add_bit(col[nod], c);
if (!unknown)
return;
viz[nod] = 1;
if (adia[nod].empty() || viz[adia[nod][i % adia[nod].size()]]) {
int x = Move(tata[nod]);
dfs(tata[nod], poz_in_adia[nod] + 1, x);
}
else {
i %= adia[nod].size();
int x = Move(adia[nod][i]);
dfs(adia[nod][i], 0, x);
}
}
void Joi(int N, int M, int A[], int B[], long long X, int T)
{
tells = 1;
proc_input(N, M, A, B, X);
}
#include <bits/stdc++.h>
using namespace std;
#include "Ioi.h"
void MessageBoard(int attr, int msg)
{
cout << "Pe panoul " << attr << " se scrie " << msg << '\n';
}
int Move(int desc)
{
cout << "Ma duc in " << desc << '\n';
int x;
cout << "Care este nr de acolo ??\n";
cin >> x;
return x;
}
namespace UF {
int tata[100010];
int g[100010];
int find(int x) {
if (tata[tata[x]] != tata[x])
tata[x] = find(tata[x]);
return tata[x];
}
bool unite(int a, int b) {
a = find(a);
b = find(b);
if (a == b)
return false;
if (g[a] > g[b])
g[a] += g[b], tata[b] = a;
else
g[b] += g[a], tata[a] = b;
return true;
}
void init() {
for (int i(0); i <= 100000; i++)
tata[i] = i, g[i] = 1;
}
}
int col[100010], colact;
vector <int> adia[100010];
int poz_in_adia[100010];
int fii[100010];
int tata[100010];
int nrcol = 7;
int biti[64];
int unknown;
bool tells;
int viz[100010];
void mk_cols(int nod)
{
if (tata[nod])
adia[nod].erase(find(adia[nod].begin(), adia[nod].end(), tata[nod]));
col[nod] = colact;
colact = (colact + 1) % nrcol;
if (tells)
MessageBoard(nod, biti[col[nod]]);
for (int i(0); i < adia[nod].size(); i++) {
poz_in_adia[adia[nod][i]] = i;
tata[adia[nod][i]] = nod;
mk_cols(adia[nod][i]);
}
}
void proc_input(int n, int m, int * a, int * b, long long x)
{
UF::init();
for (int i(0); i < m; i++) {
if (UF::unite(a[i], b[i])) {
adia[a[i]].push_back(b[i]);
adia[b[i]].push_back(a[i]);
}
}
if (x != -1) {
for (int i(0); i < nrcol; i++) {
biti[i] = x & 1ll;
x >>= 1;
}
}
else {
unknown = nrcol;
for (int i(0); i < nrcol; i++)
biti[i] = -1;
}
mk_cols(1);
}
void add_bit(int col, int bit)
{
if (biti[col] == -1)
unknown--;
biti[col] = bit;
}
void dfs(int nod, int i, int c)
{
add_bit(col[nod], c);
if (!unknown)
return;
viz[nod] = 1;
if (adia[nod].empty() || viz[adia[nod][i % adia[nod].size()]]) {
int x = Move(tata[nod]);
dfs(tata[nod], poz_in_adia[nod] + 1, x);
}
else {
i %= adia[nod].size();
int x = Move(adia[nod][i]);
dfs(adia[nod][i], 0, x);
}
}
long long Ioi(int N, int M, int A[], int B[], int P, int V, int T)
{
proc_input(N, M, A, B, -1);
dfs(P, 0, V);
long long x(0);
for (int i(0); i < nrcol; i++)
x += biti[i] << i;
return x;
}
Compilation message
Joi.cpp: In function 'void mk_cols(int)':
Joi.cpp:66:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i(0); i < adia[nod].size(); i++) {
~~^~~~~~~~~~~~~~~~~~
/tmp/ccuGNCR4.o: In function `MessageBoard(int, int)':
grader_joi.cpp:(.text+0x30): multiple definition of `MessageBoard(int, int)'
/tmp/ccQjq8Cb.o:Joi.cpp:(.text+0x30): first defined here
collect2: error: ld returned 1 exit status
Ioi.cpp: In function 'void mk_cols(int)':
Ioi.cpp:66:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i(0); i < adia[nod].size(); i++) {
~~^~~~~~~~~~~~~~~~~~
/tmp/ccsESl5B.o: In function `Move(int)':
grader_ioi.cpp:(.text+0x0): multiple definition of `Move(int)'
/tmp/ccwWA24C.o:Ioi.cpp:(.text+0xc0): first defined here
collect2: error: ld returned 1 exit status