QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#77332 | #4000. Dynamic Reachability | chenshi# | RE | 2ms | 11700kb | C++ | 2.3kb | 2023-02-14 10:25:03 | 2023-02-14 10:25:05 |
Judging History
answer
#include<cstdio>
#include<queue>
#include<iostream>
#include<bitset>
using namespace std;
const int o=50010,B=300,O=610;
int n,m,q,h[o],cnt,st[o],tp,sccn,scc[o],dfn[o],low[o],opt[o],U[o*2],V[o*2],sp[o],tot,H[o],Cnt,d[o],topo[o],id[o];
int eu[o*2],ev[o*2],col[o*2];bool vis[o],spe[o*2],spn[o];bitset<O> b[o],edg[o],rem;queue<int> Q;
struct Edge{int v,p;}e[o*2],E[o*2];
inline void ad(int U,int V){e[++cnt].v=V;e[cnt].p=h[U];h[U]=cnt;}
inline void Ad(int U,int V){E[++Cnt].v=V;E[Cnt].p=H[U];H[U]=Cnt;}
void tarjan(int nw){
dfn[nw]=low[nw]=++cnt;vis[st[++tp]=nw]=1;
for(int i=h[nw];i;i=e[i].p) if(!col[i]&&!spe[i])
if(!dfn[e[i].v]) tarjan(e[i].v),low[nw]=min(low[nw],low[e[i].v]);
else if(vis[e[i].v]) low[nw]=min(low[nw],dfn[e[i].v]);
if(dfn[nw]==low[nw]) for(st[tp+1]=0,++sccn;st[tp+1]^nw;vis[st[tp--]]=0) scc[st[tp]]=sccn;
}
int main(){
scanf("%d%d%d",&n,&m,&q);
for(int i=1;i<=m;++i) scanf("%d%d",&eu[i],&ev[i]),ad(eu[i],ev[i]);
for(int i=1;i<=q;++i){
scanf("%d%d",&opt[i],&U[i]);
if(opt[i]==2) scanf("%d",&V[i]);
}
for(int i=1;i<=q;i+=B){
for(int j=1;j<=n;++j) dfn[j]=spn[j]=0;
for(int j=1;j<=m;++j) spe[j]=0;
cnt=Cnt=sccn=tot=0;
for(int j=i;j<=q&&j<i+B;++j)
if(opt[j]==1) spe[U[j]]=1,spn[eu[U[j]]]=spn[ev[U[j]]]=1;else spn[U[j]]=spn[V[j]]=1;
for(int j=1;j<=n;++j) if(!dfn[j]) tarjan(j);
for(int j=1;j<=sccn;++j) b[j].reset(),H[j]=0;
for(int j=1;j<=n;++j) if(spn[j]) sp[id[j]=++tot]=j,b[scc[j]].set(tot);
for(int j=1;j<=n;++j) for(int k=h[j];k;k=e[k].p)
if(!col[k]&&!spe[k]&&scc[j]-scc[e[k].v]) Ad(scc[j],scc[e[k].v]),++d[scc[e[k].v]];
for(int j=1;j<=sccn;++j) if(!d[j]) Q.push(j);
for(sccn=0;!Q.empty();topo[++sccn]=Q.front(),Q.pop())
for(int j=H[Q.front()];j;j=E[j].p) if(!--d[E[j].v]) Q.push(E[j].v);
for(int j=sccn;j;--j) for(int k=H[topo[j]];k;k=E[k].p) b[topo[j]]|=b[E[k].v];
for(int j=i;j<=q&&j<i+B;++j)
if(opt[j]==1) col[U[j]]^=1;
else{
for(int k=1;k<=tot;++k) edg[k]=b[scc[sp[k]]];
for(int k=i;k<=q&&k<i+B;++k) if(opt[k]==1&&!col[U[k]]) edg[id[eu[U[k]]]].set(id[ev[U[k]]]);
for(Q.push(id[U[j]]),rem.set(),rem.reset(id[U[j]]);!Q.empty();Q.pop())
for(int k;(k=(rem&edg[Q.front()])._Find_first())<O;rem.reset(k)) Q.push(k);
printf(rem[id[V[j]]]?"NO\n":"YES\n");
}
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 11700kb
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
Dangerous Syscalls
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...
output:
NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO ...