QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#782202 | #9810. Obliviate, Then Reincarnate | A_J1e# | WA | 2ms | 5612kb | C++23 | 3.4kb | 2024-11-25 19:19:15 | 2024-11-25 19:19:15 |
Judging History
This is the latest submission verdict.
- [2024-11-26 23:19:26]
- hack成功,自动添加数据
- (/hack/1260)
- [2024-11-25 19:19:15]
- Submitted
answer
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
using i32 = int;
using i64 = long long;
using i128 = __int128;
#define int long long
const int N = 5e5 + 10;
#define endl "\n"
bool ok[N];
int n, m, q;
vector<pair<int, int>> e[N];
vector<int> e2[N];
bool st[N];
int du[N];
int du2[N];
bool spfa(int s)
{
vector<bool> inq(n + 10);
vector<int> dis(n + 10);
vector<int> cnt(n + 10);
for (int i = 0; i < n; i++)
dis[i] = 0;
queue<int> q;
q.push(s);
inq[s] = 1;
st[s] = 1;
cnt[s] = 1;
while (!q.empty())
{
int u = q.front();
q.pop();
inq[u] = 0;
for (auto i : e[u])
{
int v = i.first;
int val = i.second;
if(v == s && dis[s] < 0) return true;
if (dis[v] > dis[u] + val)
{
dis[v] = dis[u] + val;
if (!inq[v])
{
q.push(v);
st[v] = 1;
inq[v] = 1;
cnt[v]++;
if (cnt[v] > n)
return true;
}
}
}
}
return false;
}
bool tt[N];
void topu()
{
queue<int> q;
for (int i = 0; i < n; i++)
if (du[i] == 0)
q.push(i), st[i] = 1;
while (!q.empty())
{
int tmp = q.front();
q.pop();
for (auto i : e[tmp])
{
int v = i.first;
du[v]--;
if (du[v] == 0)
st[v] = 1, q.push(v);
}
}
for(int i = 0 ; i < n ; i++)
tt[i] = st[i];
for (int i = 0; i < n; i++)
{
if (!st[i])
if (spfa(i))
{
queue<int> q;
q.push(i);
while (!q.empty())
{
int tmp = q.front();
q.pop();
for (int v : e2[tmp])
if (!ok[v])
ok[v] = 1, q.push(v);
}
}
}
for(int i = 0 ; i < n ; i++)
st[i] = tt[i];
for(int i = 0 ; i < n; i++)
for(auto &v : e[i])
v.second = -v.second;
for (int i = 0; i < n; i++)
{
if (!st[i])
if (spfa(i))
{
queue<int> q;
q.push(i);
while (!q.empty())
{
int tmp = q.front();
q.pop();
for (int v : e2[tmp])
if (!ok[v])
ok[v] = 1, q.push(v);
}
}
}
}
void solve()
{
cin >> n >> m >> q;
for (int i = 1; i <= m; i++)
{
int a, b;
cin >> a >> b;
int u = ((a % n) + n) % n , v = ((u + b) % n + n) % n;
if(b == 0) continue;
du[u]++;
e[u].push_back({v, b});
e2[v].push_back(u);
}
topu();
while (q--)
{
int tmp;
cin >> tmp;
tmp = ((tmp % n) + n) % n;
if (ok[tmp])
cout << "Yes" << endl;
else
cout << "No" << endl;
}
}
signed main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
i32 t = 1;
while (t--)
solve();
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 2ms
memory: 5612kb
input:
3 2 3 1 1 -1 3 1 2 3
output:
No No No
result:
wrong answer 1st words differ - expected: 'Yes', found: 'No'