QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#86245 | #4000. Dynamic Reachability | AFewSuns | RE | 0ms | 10756kb | C++14 | 3.8kb | 2023-03-09 16:13:21 | 2023-03-09 16:13:23 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
namespace my_std{
#define ll long long
#define bl bool
ll my_pow(ll a,ll b,ll mod){
ll res=1;
if(!b) return 1;
while(b){
if(b&1) res=(res*a)%mod;
a=(a*a)%mod;
b>>=1;
}
return res;
}
ll qpow(ll a,ll b){
ll res=1;
if(!b) return 1;
while(b){
if(b&1) res*=a;
a*=a;
b>>=1;
}
return res;
}
#define db double
#define pf printf
#define pc putchar
#define fr(i,x,y) for(register ll i=(x);i<=(y);i++)
#define pfr(i,x,y) for(register ll i=(x);i>=(y);i--)
#define go(u) for(ll i=head[u];i;i=e[i].nxt)
#define enter pc('\n')
#define space pc(' ')
#define fir first
#define sec second
#define MP make_pair
#define il inline
#define inf 8e18
#define random(x) rand()*rand()%(x)
#define inv(a,mod) my_pow((a),(mod-2),(mod))
il ll read(){
ll sum=0,f=1;
char ch=0;
while(!isdigit(ch)){
if(ch=='-') f=-1;
ch=getchar();
}
while(isdigit(ch)){
sum=sum*10+(ch^48);
ch=getchar();
}
return sum*f;
}
il void write(ll x){
if(x<0){
x=-x;
pc('-');
}
if(x>9) write(x/10);
pc(x%10+'0');
}
il void writeln(ll x){
write(x);
enter;
}
il void writesp(ll x){
write(x);
space;
}
}
using namespace my_std;
#define ull unsigned long long
vector<ll> vec[50050];
ll n,m,q,head[50050],cnt=0,col[100010];
ll dfn[50050],low[50050],tot=0,blg[50050],tott=0,st[50050],top=0;
ll id[110],cntt=0,mp[50050];
bitset<300> f[50050];
bl ck[100010],pd[110],vis[50050];
struct Edge{
ll u,v;
}E[100010];
struct edge{
ll nxt,to;
}e[100010];
struct node{
ll opt,u,v;
}p[100010];
void add(ll u,ll v){
e[++cnt].nxt=head[u];
e[cnt].to=v;
head[u]=cnt;
}
void tarjan(ll u){
dfn[u]=low[u]=++tot;
vis[u]=1;
st[++top]=u;
go(u){
ll v=e[i].to;
if(ck[i]||!col[i]) continue;
if(!dfn[v]){
tarjan(v);
low[u]=min(low[u],low[v]);
}
else if(vis[v]) low[u]=min(low[u],dfn[v]);
}
if(dfn[u]==low[u]){
tott++;
blg[u]=tott;
vis[u]=0;
while(st[top]!=u){
blg[st[top]]=tott;
vis[st[top]]=0;
top--;
}
top--;
}
}
void dfs(ll u){
vis[u]=1;
fr(i,0,(ll)vec[u].size()-1){
ll v=vec[u][i];
if(!vis[v]) dfs(v);
f[u]|=f[v];
}
}
il ll cmp(ll x,ll y){
return dfn[blg[E[x].u]]<dfn[blg[E[y].u]];
}
il bl bfs(ll u,ll v){
fr(i,1,cntt) pd[i]=0;
queue<ll> Q;
fr(i,1,cntt){
if(!col[id[i]]) continue;
if(f[blg[u]][mp[E[id[i]].u]]){
pd[i]=1;
Q.push(i);
}
}
while(!Q.empty()){
ll x=Q.front();
Q.pop();
fr(i,1,cntt){
if(pd[i]||!col[id[i]]) continue;
if(f[blg[E[id[x]].v]][mp[E[id[i]].u]]){
pd[i]=1;
Q.push(i);
}
}
}
if(f[blg[u]][mp[v]]) return 1;
fr(i,1,cntt) if(pd[i]&&f[blg[E[id[i]].v]][mp[v]]) return 1;
return 0;
}
int main(){
n=read();
m=read();
q=read();
fr(i,1,m){
ll u=read(),v=read();
add(u,v);
col[i]=1;
E[i].u=u;
E[i].v=v;
}
fr(i,1,q){
p[i].opt=read();
p[i].u=read();
if(p[i].opt==2) p[i].v=read();
}
for(ll i=1;i<=q;i+=300){
ll ed=min(q,i+299);
fr(j,i,ed) if(p[j].opt==1) ck[p[j].u]=1;
fr(j,1,n) dfn[j]=low[j]=vis[j]=0;
tot=tott=0;
fr(j,1,n) if(!dfn[j]) tarjan(j);
fr(u,1,n){
for(ll j=head[u];j;j=e[j].nxt){
ll v=e[j].to;
if(ck[j]||!col[j]||blg[u]==blg[v]) continue;
vec[blg[u]].push_back(blg[v]);
}
}
cntt=0;
fr(j,1,tott) f[j].reset();
fr(j,i,ed){
if(p[j].opt==1){
id[++cntt]=p[j].u;
mp[E[p[j].u].u]=j-i;
f[blg[E[p[j].u].u]][j-i]=1;
}
else{
mp[p[j].v]=j-i;
f[blg[p[j].v]][j-i]=1;
}
}
fr(j,1,tott) vis[j]=0;
fr(j,1,tott) if(!vis[j]) dfs(j);
fr(j,i,ed){
if(p[j].opt==1) col[p[j].u]^=1;
else{
if(bfs(p[j].u,p[j].v)) pf("YES\n");
else pf("NO\n");
}
}
fr(j,i,ed) if(p[j].opt==1) ck[p[j].u]=0;
fr(j,1,tott) vec[j].clear();
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 10756kb
input:
5 6 7 1 2 1 3 2 4 3 4 3 5 4 5 2 1 5 2 2 3 1 3 1 4 2 1 4 1 3 2 1 5
output:
YES NO NO YES
result:
ok 4 lines
Test #2:
score: -100
Runtime Error
input:
50000 100000 100000 36671 44121 25592 44321 13226 46463 13060 25694 14021 20087 22881 38333 34655 47774 22868 26462 31154 48710 27491 32365 5874 47497 17622 28600 1886 14193 22315 23656 14973 22704 1335 25384 22612 34915 2852 48213 23334 25519 24342 28784 6238 36125 14598 39494 33069 34250 2123 3059...