#include "Joi.h"
#include <bits/stdc++.h>
using namespace std;
#define int long long
struct UnionFind {
vector<int> p, ranks;
UnionFind(int n) : p(n), ranks(n, 0) {
for(int i = 0; i < n; ++i) {
p[i] = i;
}
}
int find_set(int a) {
return p[a] == a ? a : p[a] = find_set(p[a]);
}
bool is_same_set(int a, int b) {
return find_set(a) == find_set(b);
}
void unite(int a, int b) {
int x = find_set(a), y = find_set(b);
if(x != y) {
if(ranks[x] > ranks[y])
p[y] = x;
else {
p[x] = y;
if(ranks[x] == ranks[y]) {
++ranks[y];
}
}
}
}
};
static vector<vector<int>> adj;
static int tim = 0;
static vector<int> ts;
static vector<int> path;
static void dfs(int u) {
ts[u] = tim++;
path.push_back(u);
for(int v : adj[u]) {
if(ts[v] == -1) {
dfs(v);
path.push_back(u);
}
}
}
static void find_tree(int n, int m, signed A[], signed B[]) {
adj.resize(n);
UnionFind uf(n);
vector<pair<int, int>> edges(m);
for(int i = 0; i < m; ++i) {
edges[i] = {min(A[i], B[i]), max(A[i], B[i])};
}
sort(edges.begin(), edges.end());
int k = 0;
for(pair<int, int> p : edges) {
int u = p.first, v = p.second;
if(!uf.is_same_set(u, v)) {
uf.unite(u, v);
adj[u].push_back(v);
adj[v].push_back(u);
++k;
}
}
assert(k == n-1);
ts.assign(n, -1);
dfs(0);
/*cout << "ts: { ";
for(int i = 0; i < n; ++i) {
cout << ts[i] << ", ";
}
cout << "}\n";
cout << "path: { ";
for(int i : path) {
cout << i << ", ";
}
cout << "}" << endl;*/
}
void Joi(signed n, signed m, signed A[], signed B[], long long X, signed T) {
int seq[60];
//cout << "seq: { ";
for(int i = 0; i < 60; ++i) {
seq[i] = ((X&(1LL << i)) > 0);
//cout << seq[i] << ", ";
}
//cout << "}" << endl;
find_tree(n, m, A, B);
for(int i = 0; i < n; ++i) {
assert(ts[i] != -1);
MessageBoard(i, seq[ts[i]%60]);
}
}
#include "Ioi.h"
#include <bits/stdc++.h>
using namespace std;
#define int long long
struct UnionFind {
vector<int> p, ranks;
UnionFind(int n) : p(n), ranks(n, 0) {
for(int i = 0; i < n; ++i) {
p[i] = i;
}
}
int find_set(int a) {
return p[a] == a ? a : p[a] = find_set(p[a]);
}
bool is_same_set(int a, int b) {
return find_set(a) == find_set(b);
}
void unite(int a, int b) {
int x = find_set(a), y = find_set(b);
if(x != y) {
if(ranks[x] > ranks[y])
p[y] = x;
else {
p[x] = y;
if(ranks[x] == ranks[y]) {
++ranks[y];
}
}
}
}
};
static vector<vector<int>> adj;
static int tim = 0;
static vector<int> ts;
static vector<int> path;
static void dfs(int u) {
ts[u] = tim++;
path.push_back(u);
for(int v : adj[u]) {
if(ts[v] == -1) {
dfs(v);
path.push_back(u);
}
}
}
static void find_tree(int n, int m, signed A[], signed B[]) {
adj.resize(n);
UnionFind uf(n);
vector<pair<int, int>> edges(m);
for(int i = 0; i < m; ++i) {
edges[i] = {min(A[i], B[i]), max(A[i], B[i])};
}
sort(edges.begin(), edges.end());
for(pair<int, int> p : edges) {
int u = p.first, v = p.second;
if(!uf.is_same_set(u, v)) {
uf.unite(u, v);
adj[u].push_back(v);
adj[v].push_back(u);
}
}
ts.assign(n, -1);
dfs(0);
}
long long Ioi(signed n, signed m, signed A[], signed B[], signed p, signed v, signed T) {
find_tree(n, m, A, B);
int seq[60];
seq[ts[p]%60] = v;
int i;
for(i = 0; i < path.size(); ++i) {
if(path[i] == p) {
break;
}
}
for(int k = 0; k < 120; ++k) {
i = (i+1)%(path.size()-1);
int res = Move(path[i]);
seq[ts[path[i]]%60] = res;
}
int X = 0;
for(int j = 0; j < 60; ++j)
X |= seq[j] << j;
return X;
}
Compilation message
Ioi.cpp: In function 'long long int Ioi(int, int, int*, int*, int, int, int)':
Ioi.cpp:82:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(i = 0; i < path.size(); ++i) {
~~^~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
832 KB |
Output is correct |
2 |
Incorrect |
5 ms |
1136 KB |
Wrong Answer [7] |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
50 ms |
5528 KB |
Output is correct |
2 |
Correct |
40 ms |
6180 KB |
Output is correct |
3 |
Correct |
36 ms |
6728 KB |
Output is correct |
4 |
Correct |
23 ms |
6872 KB |
Output is correct |
5 |
Incorrect |
24 ms |
6980 KB |
Wrong Answer [7] |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
7088 KB |
Output is correct |
2 |
Correct |
4 ms |
7088 KB |
Output is correct |
3 |
Correct |
6 ms |
7088 KB |
Output is correct |
4 |
Correct |
8 ms |
7088 KB |
Output is correct |
5 |
Correct |
6 ms |
7088 KB |
Output is correct |
6 |
Correct |
7 ms |
7088 KB |
Output is correct |
7 |
Correct |
7 ms |
7088 KB |
Output is correct |
8 |
Correct |
7 ms |
7088 KB |
Output is correct |
9 |
Correct |
19 ms |
7604 KB |
Output is correct |
10 |
Correct |
18 ms |
7860 KB |
Output is correct |
11 |
Correct |
19 ms |
8048 KB |
Output is correct |
12 |
Correct |
5 ms |
8144 KB |
Output is correct |
13 |
Correct |
6 ms |
8144 KB |
Output is correct |
14 |
Correct |
4 ms |
8144 KB |
Output is correct |
15 |
Correct |
4 ms |
8144 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
34 ms |
8444 KB |
Output is correct |
2 |
Correct |
35 ms |
8848 KB |
Output is correct |
3 |
Correct |
35 ms |
9144 KB |
Output is correct |
4 |
Correct |
24 ms |
9336 KB |
Output is correct |
5 |
Incorrect |
32 ms |
9396 KB |
Wrong Answer [7] |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
38 ms |
9964 KB |
Output is correct |
2 |
Incorrect |
39 ms |
10544 KB |
Wrong Answer [7] |
3 |
Halted |
0 ms |
0 KB |
- |