#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);
}
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) {
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);
}
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) {
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;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
1044 KB |
Output is correct |
2 |
Incorrect |
6 ms |
804 KB |
Wrong Answer [7] |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1156 ms |
263168 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
776 KB |
Output is correct |
2 |
Correct |
6 ms |
904 KB |
Output is correct |
3 |
Incorrect |
4 ms |
824 KB |
Wrong Answer [7] |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3012 ms |
79136 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3015 ms |
81436 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |