QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#794956 | #9810. Obliviate, Then Reincarnate | Legend_dy# | WA | 4ms | 16116kb | C++20 | 2.5kb | 2024-11-30 17:07:12 | 2024-11-30 17:07:13 |
Judging History
answer
#include <bits/stdc++.h>
#define int long long
using namespace std;
constexpr int N = 1e6 + 5, M = 1e6 + 5;
int ver[M], Next[M], head[N], dfn[N], low[N];
int s[N], ins[N], c[N];
vector<int> scc[N];
int tot, num, top, cnt;
void add(int x, int y) {
ver[++tot] = y, Next[tot] = head[x], head[x] = tot;
}
void tarjan(int x) {
dfn[x] = low[x] = ++num;
s[++top] = x, ins[x] = 1;
for (int i = head[x]; i; i = Next[i]) {
if (!dfn[ver[i]]) {
tarjan(ver[i]);
low[x] = min(low[x], low[ver[i]]);
}
else if (ins[ver[i]]) {
low[x] = min(low[x], dfn[ver[i]]);
}
}
if (dfn[x] == low[x]) {
cnt++;
int y;
do {
y = s[top--], ins[y] = 0;
c[y] = cnt, scc[cnt].push_back(y);
} while (x != y);
}
}
void solve() {
int n, m, t;
cin >> n >> m >> t;
vector<int> vis(n);
for (int i = 1, a, b; i <= m; i++) {
cin >> a >> b;
if (b == 0) continue;
a = (a % n + n) % n;
b = (b % n + n) % n;
add(a, (a + b) % n);
if (a == (a + b) % n) {
vis[a] = 1;
}
}
for (int i = 0; i < n; i++) {
if (!dfn[i]) tarjan(i);
}
vector<int> d(cnt + 1);
vector g(cnt + 1, vector<int>());
for (int x = 0; x < n; x++) {
for (int i = head[x]; i; i = Next[i]) {
int y = ver[i];
if (c[x] == c[y]) continue;
g[y].push_back(x); // 建反边
d[x]++;
}
}
queue<int> q;
for (int i = 1; i <= cnt; i++) {
if (scc[i].size() > 1) {
for (auto x : scc[i]) {
vis[x] = 1;
// cerr << x << "!!!\n";
}
}
if (!d[i]) {
q.push(i);
// cerr << i << "!\n";
}
}
for (int i = 0; i < n; i ++)
while (!q.empty()) {
auto u = q.front();
q.pop();
for (auto v : g[u]) {
vis[v] |= vis[u];
d[v]--;
if (!d[v]) q.push(v);
}
}
while (t--) {
int x;
cin >> x;
x = (x % n + n) % n;
if (vis[x]) {
cout << "Yes\n";
}
else cout << "No\n";
}
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int T = 1;
// cin >> T;
while(T--) {
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 15912kb
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: 15852kb
input:
3 2 3 1 1 -1 0 1 2 3
output:
No No No
result:
ok 3 tokens
Test #3:
score: 0
Accepted
time: 4ms
memory: 16116kb
input:
1 1 1 0 1000000000 -1000000000
output:
Yes
result:
ok "Yes"
Test #4:
score: -100
Wrong Answer
time: 3ms
memory: 15948kb
input:
3 2 3 0 1000000000 1 -1000000000 -1000000000 0 -1000000000
output:
No Yes No
result:
wrong answer 2nd words differ - expected: 'No', found: 'Yes'