QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#782191 | #9810. Obliviate, Then Reincarnate | A_J1e# | TL | 2ms | 5908kb | C++23 | 3.3kb | 2024-11-25 19:16:45 | 2024-11-25 19:16:47 |
Judging History
This is the latest submission verdict.
- [2024-11-26 23:19:26]
- hack成功,自动添加数据
- (/hack/1260)
- [2024-11-25 19:16:45]
- Submitted
answer
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
using i32 = int;
using i64 = long long;
using i128 = __int128;
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);
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;
}
}
int 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: 100
Accepted
time: 0ms
memory: 5716kb
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: 2ms
memory: 5908kb
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: 0ms
memory: 5616kb
input:
1 1 1 0 1000000000 -1000000000
output:
Yes
result:
ok "Yes"
Test #4:
score: 0
Accepted
time: 0ms
memory: 5876kb
input:
3 2 3 0 1000000000 1 -1000000000 -1000000000 0 -1000000000
output:
No No No
result:
ok 3 tokens
Test #5:
score: -100
Time Limit Exceeded
input:
50134 500000 500000 -154428638 -283522863 -186373509 -327130969 154999046 46750274 -933523447 349415487 -437683609 140099255 864996699 -262318199 811293034 -264299324 120273173 52410685 874944410 -52048424 445049930 -803690605 -138111276 -104634331 720288580 126597671 471164416 -348777147 -356502322...