QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#183815#4000. Dynamic ReachabilitykgqyRE 0ms9800kbC++143.5kb2023-09-19 21:19:592023-09-19 21:19:59

Judging History

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

  • [2023-09-19 21:19:59]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:9800kb
  • [2023-09-19 21:19:59]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define int long long
inline int read(){
	int w=0;char ch=getchar();
	while(!isdigit(ch)) ch=getchar();
	while(isdigit(ch)) w=w*10+ch-'0',ch=getchar();
	return w;
}
const int sz=60;
int n,m,q;
bitset<130> f[50005],g[130],cl[130];
int su[50005],sv[50005];
int sop[100005],sx[100005],sy[100005];
int visedge[50005];
vector<int> tr[50005],to[50005];
vector<int> v1,v2,v1e;
int low[50005],dfn[50005],dfncnt;
int sta[50005],tot;
int belon[50005],bk;
int deg[50005];
int mp[50005];
int outedge[50005];
void tarjan(int x){
	low[x]=dfn[x]=++dfncnt;
	sta[++tot]=x;
	for(int i=0;i<tr[x].size();i++){
		int y=tr[x][i];
		if(dfn[y]){if(!belon[y]) low[x]=min(low[x],dfn[y]);}
		else tarjan(y),low[x]=min(low[x],low[y]);
	}
	// printf("%d %d %d\n",x,low[x],dfn[x]);
	if(low[x]==dfn[x]){
		// printf("bk %d tot %d\n",bk,tot);
		// for(int i=tot;i;i--) printf("%d ",sta[i]);puts("");
		deg[++bk]=0;
		f[bk].reset();
		for(int i=sta[tot];dfn[i]>=dfn[x];i=sta[--tot]){
			belon[i]=bk;
			// printf("%d ",i);
		}
		// puts("end");
	}
}
queue<int> qq;
void init(){
	for(int i=0;i<v2.size();i++) f[belon[v2[i]]][i]=1;
	for(int u=1;u<=n;u++){
		for(int i=0;i<tr[u].size();i++){
			int v=tr[u][i];
			if(belon[u]==belon[v]) continue;
			to[belon[u]].push_back(belon[v]);
			deg[belon[v]]++;
		}
	}
	for(int i=1;i<=bk;i++) if(!deg[i]) qq.push(i);
	while(!qq.empty()){
		int u=qq.front();qq.pop();
		for(int i=0;i<to[u].size();i++){
			int v=to[u][i];
			f[v]|=f[u];
			deg[v]--;
			if(!deg[v]) qq.push(v);
		}
	}
	for(int i=0;i<v2.size();i++) for(int j=0;j<v2.size();j++){
		if(f[belon[v2[j]]][i]) cl[i][j]=1;
		else cl[i][j]=0;
	}
}
void insert(){
	for(int i=0;i<v2.size();i++){
		g[i]=cl[i];
	}
	for(int i=0;i<v1e.size();i++){
		int e=v1e[i];
		if(!outedge[e]) g[mp[su[e]]][mp[sv[e]]]=1;
	}
	// for(int i=0;i<v2.size();i++){
	// 	for(int j=0;j<v2.size();j++){
	// 		// printf("%d %d %d\n",i,j,(g[i][j]==1));
	// 	}
	// }
}
bitset<130> vis;
bool bfs(int bg,int ed){
	// printf("query %d %d\n",bg,ed);
	qq.push(bg);
	vis.set();
	vis[bg]=0;
	while(!qq.empty()){
		int u=qq.front();qq.pop();
		bitset<130> lh=(vis&g[u]);
		int len=lh.count();
		for(int i=1,nw=lh._Find_first();i<=len;i++,nw=lh._Find_next(nw)){
			// printf("%d\n",nw);
			qq.push(nw);
		}
		vis^=lh;
	}
	return !vis[ed];
}
main(){
	n=read(),m=read(),q=read();
	for(int i=1;i<=m;i++) su[i]=read(),sv[i]=read();
	for(int i=1;i<=q;i++){
		sop[i]=read();sx[i]=read();
		if(sop[i]==2) sy[i]=read();
	}
	for(int L=1,R;L<=q;L=R+1){
		R=min(q,L+sz-1);
		v1.clear(),v2.clear(),v1e.clear();
		for(int i=L;i<=R;i++){
			if(sop[i]==1) v1e.push_back(sx[i]),v1.push_back(su[sx[i]]),v1.push_back(sv[sx[i]]),visedge[sx[i]]=1;
			else v1.push_back(sx[i]),v1.push_back(sy[i]);
		}
		for(int i=1;i<=n;i++) dfn[i]=0,low[i]=0,belon[i]=0;
		dfncnt=tot=bk=0;
		sort(v1.begin(),v1.end());
		v2.push_back(v1[0]);
		for(int i=1;i<v1.size();i++) if(v1[i]!=v1[i-1]) v2.push_back(v1[i]);
		for(int i=0;i<v2.size();i++) mp[v2[i]]=i;
		for(int i=1;i<=n;i++) tr[i].clear(),to[i].clear();
		for(int i=1;i<=m;i++){
			if(!visedge[i]&&!outedge[i]) tr[su[i]].push_back(sv[i]);
			else visedge[i]=0;
		}
		// puts("tarjan begin");
		for(int i=1;i<=n;i++) if(!dfn[i]) tarjan(i);
		// puts("tarjan end");
		init();
		// puts("init end");
		for(int i=L;i<=R;i++){
			if(sop[i]==1) outedge[sx[i]]^=1;
			else{
				insert();
				// puts("insert end");
				puts(bfs(mp[sx[i]],mp[sy[i]])?"YES":"NO");
			}
		}
	}
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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...

output:


result: