QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#392095#4000. Dynamic ReachabilityHarry27182WA 0ms15808kbC++142.7kb2024-04-17 08:12:452024-04-17 08:12:45

Judging History

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

  • [2024-04-17 08:12:45]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:15808kb
  • [2024-04-17 08:12:45]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const int N=100005;
struct node{int u,v,w;}g[N];
struct Query{int op,x,y;}Q[N];
int n,m,q,bl[N],L[N],R[N],vec[N],mp[N],dfn[N],low[N],inq[N],dfx,num;
int h[N],cnt,in[N],ok[N],vis[N],col[N];bitset<128>bs[N],E[N];
struct edge{int v,nxt;}e[100005];vector<int>f[N];stack<int>st;
void add(int u,int v){e[++cnt]={v,h[u]};h[u]=cnt;}
void tarjan(int u)
{
	dfn[u]=low[u]=++dfx;st.push(u);inq[u]=1;
	for(int i=h[u];i;i=e[i].nxt)
	{
		int v=e[i].v;
		if(!dfn[v])
		{
			tarjan(v);
			low[u]=min(low[u],low[v]);
		}
		else if(inq[v])low[u]=min(low[u],dfn[v]);
	}
	if(low[u]==dfn[u])
	{
		num++;
		while(!st.empty())
		{
			int x=st.top();st.pop();inq[x]--;
			if(vis[x])bs[num].set(vis[x]-1);
			col[x]=num;if(x==u)break;
		}
	}
}
int main()
{
	//freopen("1.in","r",stdin);
	//freopen("1.out","w",stdout);
	cin.tie(0)->sync_with_stdio(0);
	cin>>n>>m>>q;
	for(int i=1;i<=m;i++)cin>>g[i].u>>g[i].v,g[i].w=1;
	int B=64;
	for(int i=1;i<=q;i++)
	{
		cin>>Q[i].op;
		if(Q[i].op==1)cin>>Q[i].x;
		else cin>>Q[i].x>>Q[i].y;
		bl[i]=(i-1)/B+1;
		if(bl[i]!=bl[i-1])L[bl[i]]=i,R[bl[i-1]]=i-1;
	}
	R[bl[q]]=q;
	for(int k=1;k<=bl[q];k++)
	{
		int l=L[k],r=R[k],tot=0;cnt=dfx=num=0;
		for(int i=1;i<=n;i++)h[i]=in[i]=vis[i]=dfn[i]=low[i]=col[i]=0,bs[i].reset(),f[i].clear();
		for(int i=1;i<=m;i++)mp[i]=0;
		for(int i=l;i<=r;i++)
		{
			if(Q[i].op==1)
			{
				mp[Q[i].x]=1;
				vec[++tot]=g[Q[i].x].u;
				vec[++tot]=g[Q[i].x].v;
			}
			else 
			{
				vec[++tot]=Q[i].x;
				vec[++tot]=Q[i].y;
			}
		}
		sort(vec+1,vec+tot+1);
		tot=unique(vec+1,vec+tot+1)-vec-1;
		for(int i=1;i<=tot;i++)vis[vec[i]]=i;
		for(int i=1;i<=m;i++)if(!mp[i]&&g[i].w==1)add(g[i].v,g[i].u);
		for(int i=1;i<=n;i++)if(!dfn[i])tarjan(i);
		for(int u=1;u<=n;u++)
		{
			for(int i=h[u];i;i=e[i].nxt)
			{
				int v=e[i].v;
				if(col[u]!=col[v])f[col[u]].emplace_back(col[v]),in[col[v]]++;
			}
		}
		queue<int>q;
		for(int i=1;i<=num;i++)if(!in[i])q.push(i);
		while(!q.empty())
		{
			int u=q.front();q.pop();
			for(int i=0;i<f[u].size();i++)
			{
				int v=f[u][i];
				bs[v]|=bs[u];in[v]--;
				if(!in[v])q.push(v); 
			}
		}
		for(int i=l;i<=r;i++)
		{
			if(Q[i].op==1)g[Q[i].x].w^=1;
			else 
			{
				for(int j=1;j<=tot;j++)E[j]=bs[col[vec[j]]];
				for(int j=l;j<=r;j++)if(Q[j].op==1&&g[Q[j].x].w==1)E[vis[g[Q[j].x].u]].set(vis[g[Q[j].x].v]-1);
				int s=vis[Q[i].x],t=vis[Q[i].y];
				for(int j=1;j<=tot;j++)ok[j]=0;
				queue<int>q;q.push(s);ok[s]=1;
				while(!q.empty())
				{
					int u=q.front();q.pop();
					for(int j=1;j<=tot;j++)if(E[u][j]&&(!ok[j]))ok[j]=1,q.push(j);
				}
				if(ok[t])cout<<"YES\n";
				else cout<<"NO\n";
			}
		}
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 15808kb

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:

NO
YES
YES
NO

result:

wrong answer 1st lines differ - expected: 'YES', found: 'NO'