QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#86702 | #4000. Dynamic Reachability | fansizhe | WA | 3035ms | 18412kb | C++23 | 3.1kb | 2023-03-10 16:35:55 | 2023-03-10 16:35:59 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int B=256;
int n,m,q;
vector<pair<int,int> > edge[50005];
int ex[100005],ey[100005];
struct Query{
int opt,x,y;
}Q[100005];
vector<int> vec;
int pos[50005];
int del[100005],vis[100005];
bitset<512> to[50005],to1[64];
int dfn[50005],low[50005],tot,ins[50005],st[50005],top,scc[50005],col;
vector<int> e[50005];
int cnt,po[50005],deg[50005];
queue<int> que;
void Tarjan(int x){
dfn[x]=low[x]=++tot;
st[++top]=x,ins[x]=1;
for(auto e:edge[x])if(!vis[e.first]&&!del[e.first]){
int y=e.second;
if(!dfn[y])Tarjan(y),low[x]=min(low[x],low[y]);
else if(ins[y])low[x]=min(low[x],dfn[y]);
}
if(low[x]==dfn[x]){
col++;int y;
do{
y=st[top--];
scc[y]=col,ins[y]=0;
}while(y!=x);
}
}
int main(){
scanf("%d%d%d",&n,&m,&q);
for(int i=1;i<=m;i++){
int x,y;scanf("%d%d",&x,&y);
edge[x].push_back(make_pair(i,y));
ex[i]=x,ey[i]=y;
}
for(int i=1;i<=q;i++){
scanf("%d",&Q[i].opt);
if(Q[i].opt==1)scanf("%d",&Q[i].x);
else scanf("%d%d",&Q[i].x,&Q[i].y);
}
for(int ql=1,qr=B;ql<=q;ql+=B,qr+=B){
qr=min(qr,q);vec.clear();
for(int i=ql;i<=qr;i++)
if(Q[i].opt==1)vec.push_back(ex[Q[i].x]),vec.push_back(ey[Q[i].x]),vis[Q[i].x]=1;
else vec.push_back(Q[i].x),vec.push_back(Q[i].y);
sort(vec.begin(),vec.end());
vec.erase(unique(vec.begin(),vec.end()),vec.end());
for(int i=0;i<vec.size();i++)pos[vec[i]]=i+1;
for(int i=1;i<=n;i++)dfn[i]=0;col=tot=0;
for(int i=1;i<=n;i++)if(!dfn[i])Tarjan(i);
while(!que.empty())que.pop();
for(int i=1;i<=col;i++)e[i].clear();
for(int i=1;i<=m;i++)if(!del[i]&&!vis[i])
if(scc[ex[i]]!=scc[ey[i]])e[scc[ex[i]]].push_back(scc[ey[i]]),deg[scc[ey[i]]]++;
for(int i=1;i<=col;i++)if(!deg[i])que.push(i);
cnt=0;
while(!que.empty()){
int x=que.front();que.pop();
po[++cnt]=x;
for(int y:e[x])if(!--deg[y])que.push(y);
}
assert(cnt==col);
for(int i=1;i<=col;i++)to[i].reset();
for(int i=0;i<vec.size();i++)to[scc[vec[i]]].set(i);
for(int i=col;i>=1;i--)
for(int y:e[po[i]])to[po[i]]|=to[y];
for(int i=0;i<vec.size();i++){
to1[i].reset();
for(int j=0;j<vec.size();j++)
if(to[scc[vec[i]]][j])to1[i].set(j);
}
for(int i=ql;i<=qr;i++)if(Q[i].opt==1)if(vis[Q[i].x]){
vis[Q[i].x]=0;
if(!del[Q[i].x])
if(!to[scc[ex[Q[i].x]]][pos[ey[Q[i].x]]-1])
to1[pos[ex[Q[i].x]]-1].set(pos[ey[Q[i].x]]-1);
}
for(int i=ql;i<=qr;i++)
if(Q[i].opt==1){
del[Q[i].x]^=1;
if(!to[scc[ex[Q[i].x]]][pos[ey[Q[i].x]]-1])
to1[pos[ex[Q[i].x]]-1].flip(pos[ey[Q[i].x]]-1);
}else{
while(!que.empty())que.pop();
int S=pos[Q[i].x]-1,T=pos[Q[i].y]-1;
que.push(S);
bitset<512> now;now.set(S);
while(!que.empty()){
int x=que.front();que.pop();
bitset<512> sta=to1[x]^(to1[x]&now);
while(sta.any()){
int y=sta._Find_first();
sta.flip(y),now.set(y);
que.push(y);
if(y==T)break;
}
if(now[T])break;
}
if(now[T])puts("YES");
else puts("NO");
}
for(int x:vec)pos[x]=0;
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 12928kb
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: 0
Accepted
time: 3035ms
memory: 18308kb
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:
ok 50000 lines
Test #3:
score: -100
Wrong Answer
time: 2965ms
memory: 18412kb
input:
50000 100000 100000 27059 36120 32335 41190 9436 29046 36520 44281 25005 39115 37096 43321 11891 38873 10439 31878 19154 25918 26756 44170 9594 16092 9920 23747 17107 35055 31401 35308 17102 35604 18635 26767 27925 29726 7012 14266 973 21483 622 41029 25685 31856 36951 46699 18103 46885 9911 18465 2...
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 28169th lines differ - expected: 'NO', found: 'YES'