#include "Joi.h"
#include <vector>
#include <algorithm>
using std::vector;
using std::fill;
namespace {
const int MAXN = 1e4;
int N;
long long X;
vector<int> G[MAXN + 10];
bool vis[MAXN + 10];
long long ii = 0;
void dfs(int u) {
if(vis[u]) return;
MessageBoard(u, bool(X & (1LL << ii)));
vis[u] = true;
ii = (ii + 1) % 60;
for(int v : G[u]) {
dfs(v);
}
}
};
void Joi(int N_, int M, int A[], int B[], long long X_, int T) {
N = N_; X = X_;
fill(G, G + N, vector<int>());
for(int i = 0; i < M; i++) {
G[A[i]].push_back(B[i]);
G[B[i]].push_back(A[i]);
}
fill(vis, vis + N, 0); ii = 0;
dfs(0);
}
#include "Ioi.h"
#include <vector>
#include <algorithm>
#include <iostream>
#include <set>
using std::vector;
using std::fill;
using std::set;
namespace {
const int MAXN = 1e4;
int N;
vector<int> G[MAXN + 10];
int pos[MAXN + 10];
set<int> child[MAXN + 10];
int par[MAXN + 10];
long long res[60 + 10];
int ii = 0;
void dfs(int u) {
pos[u] = ii;
ii = (ii + 1) % 60;
for(int v : G[u]) {
if(pos[v] != -1) continue;
par[v] = u;
child[u].insert(v);
dfs(v);
}
}
long long solve(int u) {
for(int cc = 0; cc < 120 && (child[u].size() || par[u] != -1); cc++) {
//std::cerr << "par[" << u << "] = " << par[u] << "\n";
//std::cerr << "child[" << u << "] = [";
//for(int v : child[u]) std::cerr << " " << v;
//std::cerr << "]\n";
if(!child[u].size()) {
res[pos[par[u]]] = Move(par[u]);
child[par[u]].erase(u);
u = par[u];
} else {
int v = *child[u].begin(); child[u].erase(child[u].begin());
res[pos[v]] = Move(v);
u = v;
}
}
long long X = 0;
for(long long i = 0; i < 60; i++) {
X |= res[i] << i;
//std::cerr << res[i] << " ";
}
//std::cerr << "\n";
//std::cerr << "X = " << X << "\n";
return X;
}
long long work(int S, int V) {
res[pos[S]] = V;
return solve(S);
}
};
long long Ioi(int N_, int M, int A[], int B[], int P, int V, int T) {
N = N_;
for(int i = 0; i < M; i++) {
G[A[i]].push_back(B[i]);
G[B[i]].push_back(A[i]);
}
fill(pos, pos + N, -1);
fill(res, res + 60, -1);
fill(par, par + N, -1);
fill(child, child + N, set<int>());
par[0] = -1; dfs(0);
return work(P, V);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
1696 KB |
Output is correct |
2 |
Incorrect |
4 ms |
2532 KB |
Wrong Answer [7] |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
32 ms |
5768 KB |
Output is correct |
2 |
Incorrect |
31 ms |
7308 KB |
Wrong Answer [7] |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
7520 KB |
Output is correct |
2 |
Correct |
4 ms |
7520 KB |
Output is correct |
3 |
Correct |
4 ms |
7520 KB |
Output is correct |
4 |
Correct |
6 ms |
7520 KB |
Output is correct |
5 |
Correct |
5 ms |
7520 KB |
Output is correct |
6 |
Correct |
6 ms |
7520 KB |
Output is correct |
7 |
Correct |
6 ms |
7520 KB |
Output is correct |
8 |
Correct |
5 ms |
7520 KB |
Output is correct |
9 |
Correct |
16 ms |
7764 KB |
Output is correct |
10 |
Correct |
15 ms |
8264 KB |
Output is correct |
11 |
Correct |
16 ms |
8520 KB |
Output is correct |
12 |
Correct |
4 ms |
8520 KB |
Output is correct |
13 |
Correct |
4 ms |
8520 KB |
Output is correct |
14 |
Correct |
3 ms |
8520 KB |
Output is correct |
15 |
Correct |
4 ms |
8520 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
30 ms |
8800 KB |
Wrong Answer [7] |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
31 ms |
9272 KB |
Output is correct |
2 |
Correct |
30 ms |
9656 KB |
Output is correct |
3 |
Incorrect |
30 ms |
10140 KB |
Wrong Answer [7] |
4 |
Halted |
0 ms |
0 KB |
- |