QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#86253 | #4000. Dynamic Reachability | Bird | WA | 1645ms | 11512kb | C++14 | 2.6kb | 2023-03-09 16:18:38 | 2023-03-09 16:18:42 |
Judging History
answer
#include<bits/stdc++.h>
#include<queue>
#include<bitset>
#define N 50000
#define M 100000
using namespace std;
const int B=256;
int n,m,q,head[N+5],u[M+5],v[M+5],Head[N+5];
bool col[M+5],vise[M+5];
struct edge {int to,nxt;} e[M+5],E[M+5];
struct ask
{
int opt,k,u,v;
inline void read()
{
scanf("%d",&opt);
if(opt==1) scanf("%d",&k);
else scanf("%d %d",&u,&v);
}
}a[N+5];
namespace tarjan
{
int dfn[N+5],low[N+5],tot,cur[N+5],cnt,st[N+5],top;
bool vis[N+5];
#define y e[i].to
inline void dfs(int x)
{
dfn[x]=low[x]=++tot,vis[st[++top]=x]=1;
for(int i=head[x];i;i=e[i].nxt) if(!vise[i] && col[i])
{
if(!dfn[y]) dfs(y),low[x]=min(low[x],low[y]);
else if(vis[y]) low[x]=min(low[x],dfn[y]);
}
if(low[x]==dfn[x]) for(st[top+1]=0,++cnt;st[top+1]!=x;--top)
cur[st[top]]=cnt,vis[st[top]]=0;
}
inline void solve()
{
memset(dfn+1,0,n<<2),tot=0;
memset(low+1,0,n<<2),cnt=0;
for(int i=1;i<=n;++i) if(!dfn[i]) dfs(i);
memset(Head+1,0,cnt<<2);
for(int i=1;i<=m;++i)
E[i]={cur[v[i]],Head[cur[u[i]]]},Head[cur[u[i]]]=i;
}
#undef y
}
using tarjan::cnt;
using tarjan::cur;
bitset<B*2> dis[N+5],nowe[B*2],now,temp;
int p[B*2],id[N+5],tot;
queue<int> que;
inline void add(int x) {if(!~id[x]) p[id[x]=tot++]=x;}
inline void get_dis()
{
for(int x=1;x<=cnt;++x)
{
dis[x].reset();
for(int i=Head[x];i;i=E[i].nxt) dis[x]|=dis[E[i].to];
if(~id[x]) dis[x].set(id[x]),nowe[id[x]]=dis[x];
}
}
int main()
{
scanf("%d %d %d",&n,&m,&q);
for(int i=1;i<=m;++i)
{
scanf("%d %d",u+i,v+i),col[i]=1;
e[i]={v[i],head[u[i]]},head[u[i]]=i;
}
for(int i=1;i<=q;++i) a[i].read();
for(int t=1;t<=q;t+=B)
{
for(int i=t;i<t+B;++i)
if(a[i].opt==1) vise[a[i].k]=1;
tarjan::solve(),tot=0;
memset(id+1,-1,cnt<<2);
for(int i=t;i<t+B;++i)
if(a[i].opt==1) add(cur[u[a[i].k]]),add(cur[v[a[i].k]]);
else add(cur[a[i].u]),add(cur[a[i].v]);
get_dis();
for(int i=t;i<t+B;++i) if(a[i].opt==1)
{
a[i].u=id[cur[u[a[i].k]]],a[i].v=id[cur[v[a[i].k]]];
!dis[p[a[i].u]][a[i].v] && (nowe[a[i].u].set(a[i].u,col[a[i].k]),1);
}
for(int i=t;i<min(q+1,t+B);++i)
if(a[i].opt==1) vise[a[i].k]=0,col[a[i].k]^=1,
!dis[p[a[i].u]][a[i].v] && (nowe[a[i].u].set(a[i].v,col[a[i].k]),1);
else
{
now.set(),que.push(id[cur[a[i].u]]),now.reset(que.front());
while(!que.empty())
{
int x=que.front();que.pop(),temp=nowe[x]&now;
for(int y=temp._Find_first();y<tot;y=temp._Find_next(y))
que.push(y),now.reset(y);
}
puts(now[id[cur[a[i].v]]]?"NO":"YES");
}
memset(id,0,tot);
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 5520kb
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
Wrong Answer
time: 1645ms
memory: 11512kb
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 ...
result:
wrong answer 5211th lines differ - expected: 'NO', found: 'YES'