QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#786013 | #9810. Obliviate, Then Reincarnate | Empty_Dust | RE | 0ms | 3852kb | C++23 | 3.1kb | 2024-11-26 19:55:28 | 2024-11-26 19:55:37 |
Judging History
This is the latest submission verdict.
- [2024-11-26 23:19:26]
- hack成功,自动添加数据
- (/hack/1260)
- [2024-11-26 19:55:28]
- Submitted
answer
#include <bits/stdc++.h>
#define ranges std::ranges
#define views std::views
using u32 = unsigned;
using i64 = long long;
using u64 = unsigned long long;
using pii = std::pair<int, int>;
using a3 = std::array<int, 3>;
using a4 = std::array<int, 4>;
const int N = 1e6;
const int MAXN = 1e6 + 10;
const int inf = 1e9;
// const int mod = 1e9 + 7;
const int mod = 998244353;
struct SCC {
int n;
std::vector<std::vector<int>> adj;
std::vector<int> stk;
std::vector<int> dfn, low, bel;
int cur, cnt;
SCC() {}
SCC(int n) {
init(n);
}
void init(int n) {
this->n = n;
adj.assign(n, {});
dfn.assign(n, -1);
low.resize(n);
bel.assign(n, -1);
stk.clear();
cur = cnt = 0;
}
void addEdge(int u, int v) {
adj[u].push_back(v);
}
void dfs(int x) {
dfn[x] = low[x] = cur++;
stk.push_back(x);
for (auto y : adj[x]) {
if (dfn[y] == -1) {
dfs(y);
low[x] = std::min(low[x], low[y]);
}
else if (bel[y] == -1) {
low[x] = std::min(low[x], dfn[y]);
}
}
if (dfn[x] == low[x]) {
int y;
do {
y = stk.back();
bel[y] = cnt;
stk.pop_back();
} while (y != x);
cnt++;
}
}
std::vector<int> work() {
for (int i = 0; i < n; i++) {
if (dfn[i] == -1) {
dfs(i);
}
}
int m = n / 2;
std::vector<int> ans(m), vis(n);
for (int i = 0;i < m;++i) {
if (bel[i] == bel[i + m]) {
vis[i] = 1;
vis[i + m] = 1;
ans[i] = 1;
// std::cout << i << ' ';
}
}
auto dfs2 = [&](auto&& self, int u, int p) ->bool {
if (vis[u])return ans[u];
vis[u] = 1;
for (int v : adj[u])if (v != p) {
if (self(self, v, u)) {
ans[u] = 1;
}
}
return ans[u];
};
for (int i = 0;i < n;++i) {
if (!vis[i])
dfs2(dfs2, i, -1);
}
return ans;
}
};
void solve() {
int n, m, q;std::cin >> n >> m >> q;
SCC scc(2 * n);
int N = 2 * n;
for (int i = 0; i < m;++i) {
int a, b;std::cin >> a >> b;
a--;
a = ((a % n) + n) % n;
b = ((b % N) + N) % N;
b = a + b;
scc.addEdge(a, b);
// std::cout << a << ' ' << b << '\n';
scc.addEdge(a + n, (b + n) % N);
// std::cout << a + n << ' ' << (b + n) % N << '\n';
}
auto ans = scc.work();
for (int i = 0;i < q;++i) {
int x;std::cin >> x;x--;
std::cout << (ans[x] ? "Yes" : "No") << '\n';
}
}
signed main() {
std::ios::sync_with_stdio(false);
std::cin.tie(0), std::cout.tie(0);
int t = 1;
while (t--) {
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3852kb
input:
3 2 3 1 1 -1 3 1 2 3
output:
Yes Yes No
result:
ok 3 tokens
Test #2:
score: 0
Accepted
time: 0ms
memory: 3604kb
input:
3 2 3 1 1 -1 0 1 2 3
output:
No No No
result:
ok 3 tokens
Test #3:
score: -100
Runtime Error
input:
1 1 1 0 1000000000 -1000000000