QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#798581 | #9810. Obliviate, Then Reincarnate | ucup-team4975 | RE | 0ms | 0kb | C++14 | 2.0kb | 2024-12-04 15:03:33 | 2024-12-04 15:03:33 |
Judging History
answer
#define LOCAL
#include <bits/stdc++.h>
#define fir first
#define sec second
#define pbk push_back
#ifdef LOCAL
#define FINISH cerr << "FINISH" << endl;
#else
#define FINISH ;
#endif
#ifdef LOCAL
#define debug(x) cerr << setw(4) << #x << " == " << x << endl
#else
#define debug(x)
#endif
#ifdef LOCAL
#define debugv(x) \
cerr << setw(4) << #x << ":: "; \
for (auto i : x) \
cerr << i << " "; \
cerr << endl
#else
#define debugv(x)
#endif
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
ostream& operator<<(ostream& out, PII& x)
{
out << x.fir << " " << x.sec << endl;
return out;
}
const ll MOD = 998244353;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const int N = 200020;
ll negmod(ll x,ll mod){
return ((x%mod)+mod)%mod;
}
void solve()
{
ll n,m,q;
cin>>n>>m>>q;
vector<vector<ll>> G(n+1,vector<ll>());
for(int i=0;i<m;i++){
ll a,b;
cin>>a>>b;
if(b!=0)G[negmod(a,n)].push_back(b);
}
stack<ll> st;
vector<ll> belong(n),dfn(n),low(n),h(n);
vector<bool> ans(n);
ll cnt=0,T=0;
function<void(ll)> tarjan=[&](ll d){
ll u=negmod(d,n);
dfn[u]=low[u]=++T;
for(ll y:G[u]){
ll v=negmod(d+y,n);
if(!dfn[v]){
h[v]=d+y;
tarjan(v);
low[u]=min(low[u],low[v]);
}
else if(!belong[v]){
low[u]=min(low[u],dfn[v]);
if(h[v]!=d+y)ans[v]=true;
}
ans[u]=ans[u]|ans[v];
}
if(dfn[u]==low[u]){
belong[u]=++cnt;
while(st.top()!=u){
ll v=st.top();st.pop();
belong[v]=cnt;
ans[v]=ans[v]|ans[u];
}
st.pop();
}
return;
};
for(ll i=0;i<n;i++){
if(!dfn[i]){
h[i]=i;
tarjan(i);
}
}
while(q--){
ll x;cin>>x;
x=negmod(x,n);
if(ans[x])cout<<"Yes\n";
else cout<<"No\n";
}
return;
}
int main()
{
// ios::sync_with_stdio(false);
// cin.tie(nullptr);
// cout.tie(nullptr);
int T = 1;
//cin >> T;
while (T--) {
solve();
}
return 0;
}
详细
Test #1:
score: 0
Runtime Error
input:
3 2 3 1 1 -1 3 1 2 3