#include <bits/stdc++.h>
using namespace std;
const int MAXN = 10000;
int szt[MAXN], psb[MAXN], psl[MAXN], inc[MAXN], fth[MAXN];
bitset<MAXN> oki;
vector<int> ied[MAXN], edg[MAXN], lin[MAXN];
#ifdef HOME
int mess[MAXN];
void MessageBoard(int x, int v) {
mess[x] = v; }
int Move(int x) {
return mess[x]; }
#endif
void MessageBoard(int x, int v);
void dfsJoi1(int x) {
oki[x] = true; szt[x] = 1;
sort(ied[x].begin(), ied[x].end());
for (int y : ied[x]) { if (!oki[y]) {
fth[y] = x; dfsJoi1(y);
edg[x].push_back(y); szt[x] += szt[y]; } } }
void dfsJoi3(int x, int c) {
psl[x] = lin[c].size(); lin[c].push_back(x);
for (int y : edg[x]) {
if (inc[y] == c) {
dfsJoi3(y, c); lin[c].push_back(x); } } }
int tot;
void dfsJoi2(int x, long long v) {
if (szt[x] >= 60 and inc[x] == -1) {
vector<int> que(1, x); ++tot;
for (int i = 0; i < 60; ++i) {
int cr = que[i]; inc[cr] = tot;
psb[cr] = i;
if (v > 0) {
MessageBoard(cr, (v >> psb[cr]) & 1); }
for (int nx : edg[cr]) {
if (que.size() < 60) {
que.push_back(nx); } } }
dfsJoi3(x, tot); }
else if (szt[x] < 60 and inc[x] == -1) {
int nr = 0, ax = x;
while (inc[ax] == -1) {
++nr; ax = fth[ax]; }
int ps = ((120 - nr) + psl[ax]) % lin[inc[ax]].size();
psb[x] = psb[lin[inc[ax]][ps]];
if (v > 0) {
MessageBoard(x, (v >> psb[x]) & 1); } }
for (int y : edg[x]) {
dfsJoi2(y, v); } }
void Precalculate(int n, int m, int ls1[], int ls2[], long long x) {
oki.reset(); tot = -1;
for (int i = 0; i < n; ++i) {
lin[i].clear(); edg[i].clear(); ied[i].clear();
psb[i] = inc[i] = fth[i] = psl[i] = szt[i] = -1; }
for (int i = 0; i < m; ++i) {
int x = ls1[i], y = ls2[i];
ied[x].push_back(y); ied[y].push_back(x); }
dfsJoi1(0); dfsJoi2(0, x); }
void Joi(int n, int m, int ls1[], int ls2[], long long x, int t) {
Precalculate(n, m, ls1, ls2, x); }
/*
int Move(int x);
long long Ioi(int n, int m, int ls1[], int ls2[], int p, int v, int t) {
Precalculate(n, m, ls1, ls2, -1); long long x = ((1LL * v) << psb[p]); int nr = 0;
while (inc[p] == -1) {
p = fth[p];
if (inc[p] == -1) {
x |= (Move(p) << psb[p]); ++nr; } }
for (int i = psl[p]; nr != 120; i = (i + 1) % lin[inc[p]].size(), ++nr) {
int cr = lin[inc[p]][i]; x |= ((1LL * Move(cr)) << psb[cr]); }
return x; }
*/
#ifdef HOME
int main(void) {
freopen("amusement.in", "r", stdin);
freopen("amusement.out", "w", stdout);
int n, m, p, t; long long x; cin >> n >> m >> x >> p >> t;
int *ls1 = new int[m], *ls2 = new int[m];
for (int i = 0; i < m; ++i) {
cin >> ls1[i] >> ls2[i]; }
Joi(n, m, ls1, ls2, x, t);
cout << (Ioi(n, m, ls1, ls2, p, mess[p], t) == x ? "Yes\n" : "No\n");
return 0; }
#endif
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 10000;
int szt[MAXN], psb[MAXN], psl[MAXN], inc[MAXN], fth[MAXN];
bitset<MAXN> oki;
vector<int> ied[MAXN], edg[MAXN], lin[MAXN];
#ifdef HOME
int mess[MAXN];
void MessageBoard(int x, int v) {
mess[x] = v; }
int Move(int x) {
return mess[x]; }
#endif
/*
void MessageBoard(int x, int v);
*/
void dfsJoi1(int x) {
oki[x] = true; szt[x] = 1;
sort(ied[x].begin(), ied[x].end());
for (int y : ied[x]) { if (!oki[y]) {
fth[y] = x; dfsJoi1(y);
edg[x].push_back(y); szt[x] += szt[y]; } } }
void dfsJoi3(int x, int c) {
psl[x] = lin[c].size(); lin[c].push_back(x);
for (int y : edg[x]) {
if (inc[y] == c) {
dfsJoi3(y, c); lin[c].push_back(x); } } }
int tot;
void dfsJoi2(int x, long long v) {
if (szt[x] >= 60 and inc[x] == -1) {
vector<int> que(1, x); ++tot;
for (int i = 0; i < 60; ++i) {
int cr = que[i]; inc[cr] = tot;
psb[cr] = i;
// if (v > 0) {
// MessageBoard(cr, (v >> psb[cr]) & 1); }
for (int nx : edg[cr]) {
if (que.size() < 60) {
que.push_back(nx); } } }
dfsJoi3(x, tot); }
else if (szt[x] < 60 and inc[x] == -1) {
int nr = 0, ax = x;
while (inc[ax] == -1) {
++nr; ax = fth[ax]; }
int ps = ((120 - nr) + psl[ax]) % lin[inc[ax]].size();
psb[x] = psb[lin[inc[ax]][ps]];
// if (v > 0) {
// MessageBoard(x, (v >> psb[x]) & 1); }
}
for (int y : edg[x]) {
dfsJoi2(y, v); } }
void Precalculate(int n, int m, int ls1[], int ls2[], long long x) {
oki.reset(); tot = -1;
for (int i = 0; i < n; ++i) {
lin[i].clear(); edg[i].clear(); ied[i].clear();
psb[i] = inc[i] = fth[i] = psl[i] = szt[i] = -1; }
for (int i = 0; i < m; ++i) {
int x = ls1[i], y = ls2[i];
ied[x].push_back(y); ied[y].push_back(x); }
dfsJoi1(0); dfsJoi2(0, x); }
void Joi(int n, int m, int ls1[], int ls2[], long long x, int t) {
Precalculate(n, m, ls1, ls2, x); }
int Move(int x);
long long Ioi(int n, int m, int ls1[], int ls2[], int p, int v, int t) {
Precalculate(n, m, ls1, ls2, -1); long long x = ((1LL * v) << psb[p]); int nr = 0;
while (inc[p] == -1) {
p = fth[p];
if (inc[p] == -1) {
x |= (Move(p) << psb[p]); ++nr; } }
for (int i = psl[p]; nr != 120; i = (i + 1) % lin[inc[p]].size(), ++nr) {
int cr = lin[inc[p]][i]; x |= ((1LL * Move(cr)) << psb[cr]); }
return x; }
#ifdef HOME
int main(void) {
freopen("amusement.in", "r", stdin);
freopen("amusement.out", "w", stdout);
int n, m, p, t; long long x; cin >> n >> m >> x >> p >> t;
int *ls1 = new int[m], *ls2 = new int[m];
for (int i = 0; i < m; ++i) {
cin >> ls1[i] >> ls2[i]; }
Joi(n, m, ls1, ls2, x, t);
cout << (Ioi(n, m, ls1, ls2, p, mess[p], t) == x ? "Yes\n" : "No\n");
return 0; }
#endif
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
4 ms |
2168 KB |
Wrong Answer [7] |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
32 ms |
6552 KB |
Wrong Answer [7] |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
4 ms |
2152 KB |
Wrong Answer [7] |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
34 ms |
6572 KB |
Wrong Answer [7] |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
31 ms |
6596 KB |
Wrong Answer [7] |
2 |
Halted |
0 ms |
0 KB |
- |