QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#184006#4000. Dynamic ReachabilitymaoyitingWA 264ms28616kbC++142.0kb2023-09-20 10:14:492023-09-20 10:14:50

Judging History

你现在查看的是最新测评结果

  • [2023-09-20 10:14:50]
  • 评测
  • 测评结果:WA
  • 用时:264ms
  • 内存:28616kb
  • [2023-09-20 10:14:49]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const int N=1e5+5,B=400;
int n,m,q,u[N],v[N],ok[N],op[N],k[N],x[N],y[N],cnt,upd[N],tmp,tim,dfn[N],low[N],top,s[N],tot,bl[N],t,c[N],id[N],vis[N];
vector<int>g[N],g2[N];
vector<pair<int,int> >gupd[N];
bitset<2*B+5>f[N],vi,h;
void tarjan(int x){
	dfn[x]=low[x]=++tim,s[++top]=x;
	for(int i:g[x]) if(ok[i]&&!upd[i]){
		int y=v[i];
		if(!dfn[y]) tarjan(y),low[x]=min(low[x],low[y]);
		else if(!bl[y]) low[x]=min(low[x],dfn[y]);
	}
	if(dfn[x]==low[x]){
		tot++;
		do{bl[tmp=s[top--]]=tot;}while(tmp!=x);
	}
}
void dfs(int x){
	if(vis[x]) return ;
	vis[x]=1;
	for(int y:g2[x]) dfs(y),f[x]|=f[y];
}
bool qry(int s,int t){
	queue<int>q;
	vi.reset(),q.push(s),vi.set(id[s]);
	while(q.size()){
		int x=q.front();q.pop();
		for(auto p:gupd[x]){
			int y=p.first;
			if(ok[p.second]&&!vi[id[y]]) q.push(y),vi.set(id[y]);
		}
		h=f[x]&~vi;
		for(int y=h._Find_first();y^h.size();y=h._Find_next(y))
			q.push(y),vi.set(id[y]);
	}
	return vi[id[t]];
}
void solve(int l,int r){
	for(int i=l;i<=r;i++)
		if(op[i]==1) upd[k[i]]=1;
	for(int i=1;i<=n;i++) dfn[i]=bl[i]=0;
	tot=t=0;
	for(int i=1;i<=n;i++) if(!dfn[i]) tarjan(i);
	for(int i=1;i<=tot;i++)
		g2[i].clear(),gupd[i].clear(),vis[i]=0,f[i].reset();
	for(int i=1;i<=m;i++)
		if(ok[i]&&!upd[i]&&bl[u[i]]!=bl[v[i]])
			g2[bl[u[i]]].push_back(bl[v[i]]);
	for(int i=l;i<=r;i++){
		c[++t]=bl[x[i]],c[++t]=bl[y[i]];
		if(op[i]==1) gupd[c[t-1]].push_back({c[t],k[i]}),upd[k[i]]=0;
	}
	sort(c+1,c+1+t),t=unique(c+1,c+1+t)-c-1;
	for(int i=1;i<=t;i++) f[c[i]].set(id[c[i]]=i);
	for(int i=1;i<=tot;i++) dfs(i);
	for(int i=l;i<=r;i++){
		if(op[i]==1) ok[k[i]]^=1;
		else puts(qry(bl[x[i]],bl[y[i]])?"YES":"NO");
	}
}
signed main(){
	scanf("%d%d%d",&n,&m,&q);
	for(int i=1;i<=m;i++)
		scanf("%d%d",&u[i],&v[i]),ok[i]=1,
		g[u[i]].push_back(i);
	for(int i=1,lst=0;i<=q;i++){
		scanf("%d",&op[i]);
		if(op[i]==1) scanf("%d",&k[i]),x[i]=u[k[i]],v[i]=v[k[i]];
		else scanf("%d%d",&x[i],&y[i]);
		if(++cnt==B||i==q) solve(lst+1,i),lst=i;
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 15992kb

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: 264ms
memory: 28616kb

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 201st lines differ - expected: 'NO', found: 'YES'