#include "Joi.h"
#include <bits/stdc++.h>
#define ll long long
using namespace std;
struct DSU {
vector <int> par;
int n;
inline void init(int _n) {
n = _n;
par.resize(n + 1, 0);
}
int root(int x) {
if(par[x] == 0) return x;
return par[x] = root(par[x]);
}
inline void join(int x, int y) {
x = root(x), y = root(y);
if(x != y) {
par[x] = y;
}
}
};
static vector < vector <int> > g;
static void make_mst(int n, int m, int A[], int B[]) {
DSU dsu; dsu.init(n);
g.resize(n);
for(int i = 0; i < m; i++) {
if(dsu.root(A[i]) != dsu.root(B[i])) {
dsu.join(A[i], B[i]);
g[A[i]].push_back(B[i]);
g[B[i]].push_back(A[i]);
}
}
}
static vector < vector <int> > group;
static vector <int> bit;
static void dfs(int nod, int par, int &cur) {
if(cur == 60) {
return ;
}
bit[nod] = cur++;
for(auto it : g[nod]) {
if(it != par) {
dfs(it, nod, cur);
}
}
}
static vector <int> vis;
static int now;
static void dfs1(int nod, int par) {
if(bit[nod] == -1) {
now++;
for(auto it : group[par]) {
vis[it] = now;
}
for(auto it : group[par]) {
int cnt = 0;
for(auto son : g[it]) {
if(vis[son] == now) {
cnt++;
}
}
if(cnt == 1 && it != par) {
bit[nod] = bit[it];
group[nod].push_back(nod);
for(auto son : group[par]) {
if(son != it) {
group[nod].push_back(son);
}
}
break;
}
}
}
for(auto it : g[nod]) {
if(it != par) {
dfs1(it, nod);
}
}
}
void Joi(int N, int M, int A[], int B[], long long X, int T) {
make_mst(N, M, A, B);
bit.resize(N, -1);
int cur = 0;
dfs(0, -1, cur);
group.resize(N);
int i;
for(i = 0; i < N; i++) {
if(bit[i] > -1) {
group[0].push_back(i);
}
}
for(i = 1; i < N; i++) {
if(bit[i] > -1) {
group[i] = group[0];
}
}
vis.resize(N);
dfs1(0, -1);
vector <bool> sol(N);
for(i = 0; i < N; i++) {
sol[i] = ((X & (1LL << bit[i])) > 0);
}
for(i = 0; i < N; i++) {
MessageBoard(i, sol[i]);
}
}
#include "Ioi.h"
#include <bits/stdc++.h>
#define ll long long
using namespace std;
struct DSU {
vector <int> par;
int n;
inline void init(int _n) {
n = _n;
par.resize(n + 1, 0);
}
int root(int x) {
if(par[x] == 0) return x;
return par[x] = root(par[x]);
}
inline void join(int x, int y) {
x = root(x), y = root(y);
if(x != y) {
par[x] = y;
}
}
};
static vector < vector <int> > g;
static void make_mst(int n, int m, int A[], int B[]) {
DSU dsu; dsu.init(n);
g.resize(n);
for(int i = 0; i < m; i++) {
if(dsu.root(A[i]) != dsu.root(B[i])) {
dsu.join(A[i], B[i]);
g[A[i]].push_back(B[i]);
g[B[i]].push_back(A[i]);
}
}
}
static vector < vector <int> > group;
static vector <int> bit;
static void dfs(int nod, int par, int &cur) {
if(cur == 60) {
return ;
}
bit[nod] = cur++;
for(auto it : g[nod]) {
if(it != par) {
dfs(it, nod, cur);
}
}
}
static vector <int> vis;
static int now;
static void dfs1(int nod, int par) {
if(bit[nod] == -1) {
now++;
for(auto it : group[par]) {
vis[it] = now;
}
for(auto it : group[par]) {
int cnt = 0;
for(auto son : g[it]) {
if(vis[son] == now) {
cnt++;
}
}
if(cnt == 1 && it != par) {
bit[nod] = bit[it];
group[nod].push_back(nod);
for(auto son : group[par]) {
if(son != it) {
group[nod].push_back(son);
}
}
break;
}
}
}
for(auto it : g[nod]) {
if(it != par) {
dfs1(it, nod);
}
}
}
void solve(int nod, ll &ans) {
vis[nod] = 0;
for(auto it : g[nod]) {
if(vis[it] == 1) {
ans += Move(it) * (1LL << bit[it]);
solve(it, ans);
Move(nod);
}
}
}
long long Ioi(int N, int M, int A[], int B[], int P, int V, int T) {
make_mst(N, M, A, B);
bit.resize(N, -1);
int cur = 0;
dfs(0, -1, cur);
group.resize(N);
int i;
for(i = 0; i < N; i++) {
if(bit[i] > -1) {
group[0].push_back(i);
}
}
for(i = 1; i < N; i++) {
if(bit[i] > -1) {
group[i] = group[0];
}
}
vis.resize(N);
dfs1(0, -1);
fill(vis.begin(), vis.end(), 0);
for(auto it : group[P]) {
vis[it] = 1;
}
ll ans = V * (1LL << bit[P]);
solve(P, ans);
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
768 KB |
Output is correct |
2 |
Correct |
5 ms |
896 KB |
Output is correct |
3 |
Correct |
6 ms |
900 KB |
Output is correct |
4 |
Correct |
5 ms |
896 KB |
Output is correct |
5 |
Correct |
6 ms |
896 KB |
Output is correct |
6 |
Correct |
5 ms |
940 KB |
Output is correct |
7 |
Correct |
5 ms |
1156 KB |
Output is correct |
8 |
Correct |
4 ms |
900 KB |
Output is correct |
9 |
Correct |
7 ms |
1028 KB |
Output is correct |
10 |
Correct |
5 ms |
768 KB |
Output is correct |
11 |
Runtime error |
205 ms |
263168 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
12 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1146 ms |
263168 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
896 KB |
Output is correct |
2 |
Correct |
4 ms |
896 KB |
Output is correct |
3 |
Correct |
5 ms |
932 KB |
Output is correct |
4 |
Correct |
11 ms |
2332 KB |
Output is correct |
5 |
Correct |
11 ms |
2420 KB |
Output is correct |
6 |
Correct |
12 ms |
2368 KB |
Output is correct |
7 |
Correct |
11 ms |
2420 KB |
Output is correct |
8 |
Correct |
11 ms |
2332 KB |
Output is correct |
9 |
Correct |
41 ms |
10520 KB |
Output is correct |
10 |
Correct |
49 ms |
10604 KB |
Output is correct |
11 |
Correct |
43 ms |
10488 KB |
Output is correct |
12 |
Correct |
4 ms |
896 KB |
Output is correct |
13 |
Correct |
5 ms |
896 KB |
Output is correct |
14 |
Correct |
5 ms |
776 KB |
Output is correct |
15 |
Correct |
4 ms |
896 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3101 ms |
79048 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3046 ms |
87368 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |