QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#338324#4000. Dynamic ReachabilityLarunatrecyWA 4901ms31240kbC++142.4kb2024-02-25 20:34:382024-02-25 20:34:38

Judging History

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

  • [2024-02-25 20:34:38]
  • 评测
  • 测评结果:WA
  • 用时:4901ms
  • 内存:31240kb
  • [2024-02-25 20:34:38]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const int N = 1e5+7+7;
const int B = 1000;
bitset<2*B+3> F[N/2],E[B*2+2],cur;
int n,m,q,deg[N],ord[N],dft=0;
vector<int> G[N];
void add(int x,int y)
{
	G[x].push_back(y);
}
int u[N],v[N];
int qc[N],qu[N],qv[N],col[N];
bool key[N],cut[N];
int spec[N],id[N],idx=0;
int scc[N],low[N],dfn[N],num=0,cnt=0;
bool ins[N];
stack<int> st;
void tarjan(int x)
{
	dfn[x]=low[x]=++num;
	ins[x]=1;
	st.push(x);
	for(int y:G[x])
	{
		if(!dfn[y])
		{
			tarjan(y);
			low[x]=min(low[x],low[y]);
		}
		else if(ins[y])low[x]=min(low[x],dfn[y]);
	}
	if(dfn[x]==low[x])
	{
		int c=++cnt;
		int y=0;
		do
		{
			y=st.top();
			scc[y]=c;
			st.pop();
			ins[y]=0;
		}while(y!=x);
	}
}
queue<int> Q;
vector<int> S[N];
void init()
{
	for(int i=1;i<=cnt;i++)S[i].clear();
	for(int i=1;i<=n;i++)dfn[i]=low[i]=scc[i]=id[i]=0,ins[i]=key[i]=0,G[i].clear();
	for(int i=1;i<=idx;i++)spec[i]=0,F[i].reset();
	for(int i=1;i<=m;i++)cut[i]=0;
	dft=idx=cnt=num=0;
}
void qsolve(int l,int r)
{
	for(int i=l;i<=r;i++)
	if(qc[i]==1)key[u[qu[i]]]=key[v[qu[i]]]=1,cut[qu[i]]=1;
	else key[qu[i]]=key[qv[i]]=1;
	for(int i=1;i<=m;i++)if(!cut[i]&&col[i])add(u[i],v[i]);
	for(int i=1;i<=n;i++)if(!dfn[i])tarjan(i);
	for(int i=1;i<=m;i++)if(!cut[i]&&col[i]&&scc[u[i]]!=scc[v[i]])S[scc[u[i]]].push_back(scc[v[i]]),deg[scc[v[i]]]++;
	for(int i=1;i<=cnt;i++)if(!deg[i])Q.push(i);
	while(!Q.empty())
	{
		int x=Q.front();
		Q.pop();
		ord[++dft]=x;
		for(int y:S[x])
		{
			--deg[y];
			if(!deg[y])Q.push(y);
		}
	}
	for(int i=1;i<=n;i++)if(key[i])spec[id[i]=++idx]=i,F[scc[i]][idx]=1;
	for(int i=dft;i>=1;i--){int x=ord[i];for(int y:S[x])F[x]|=F[y];}
	for(int j=l;j<=r;j++)
	if(qc[j]==1) col[qu[j]]^=1;
	else 
	{
		for(int i=1;i<=idx;i++)E[i]=F[scc[spec[i]]];
		for(int i=l;i<=r;i++)if(qc[i]==1&&col[qu[i]])E[id[u[qu[i]]]][id[v[qu[i]]]]=1;
		cur.set();
		cur.reset(id[qu[j]]);
		Q.push(id[qu[j]]);
		while(!Q.empty())
		{
			int x=Q.front();
			Q.pop();
			for(int y;(y=(cur&E[x])._Find_first())<=idx;cur.reset(y))
		 	Q.push(y);
		}
		if(cur[id[qv[j]]])printf("NO\n");
		else printf("YES\n");
	}
	init();
}
int main()
{
	cin>>n>>m>>q;
	for(int i=1;i<=m;i++)scanf("%d %d",&u[i],&v[i]),col[i]=1;
	for(int i=1;i<=q;i++)
	{
		scanf("%d %d",&qc[i],&qu[i]);
		if(qc[i]==2)scanf("%d",&qv[i]);
	}
	for(int i=1;i<=q;i+=B)qsolve(i,min(i+B-1,q));
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 4901ms
memory: 31240kb

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