QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#410789#4000. Dynamic ReachabilityChrysanthBlossomWA 5307ms7944kbC++143.0kb2024-05-14 14:56:242024-05-14 14:56:24

Judging History

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

  • [2024-05-14 14:56:24]
  • 评测
  • 测评结果:WA
  • 用时:5307ms
  • 内存:7944kb
  • [2024-05-14 14:56:24]
  • 提交

answer

#include<bits/stdc++.h> 
#include<string>
#define ri register int
#define ll long long
#define mkp make_pair
using namespace std;
const int maxn=5e4+7;
int n,m,q;
int cnt,head[maxn],to[maxn<<1],nxt[maxn<<1];
int d[maxn];
void add(int u,int v){
	++cnt;
	d[v]++;
	to[cnt]=v;
	nxt[cnt]=head[u];
	head[u]=cnt;
}
struct opt{
	int op,u,v;
	int id;
}qry[maxn<<1];
vector<pair<int,int> >edge;
const int B=32;
bool tongxing[maxn<<1];
int vis[maxn];
vector<int>pnt;
namespace Small_G{
	int ed[65][65];
	ll fr[65];
	bool vis[65];
	void clear(){
		memset(ed,0,sizeof(ed));
		for(ri i=1;i<=64;i++){
			fr[i]=0;
		}
	}
	void change(int u,int v){
		ed[u][v]^=1;
	}
	int n;
	bool find(int u,int goal){
		if(u==goal)return 1;
		vis[u]=1;
//		cout<<u<<endl;
		for(ri v=1;v<=n;v++){
			if(ed[u][v]&&vis[v]){
				cout<<"YOUDIE\n";
				exit(0);
			}
			if(ed[u][v]&&!vis[v]){
				if(find(v,goal))return 1;
			}
		}
		return 0;
	}
	bool kd(int u,int v){
		memset(vis,0,sizeof(vis));
		return find(u,v);
	}
} 
struct my_queue{
	int num[maxn];
	int head,tail;
	void clear(){
		head=1,tail=0;
	}
	void push(int x){
		num[++tail]=x;
	} 
	void pop(){
		++head;
	}
	int front(){
		return num[head];
	}
	bool empty(){
		return tail<head;
	}
}qq;
ll kd[maxn];
void solve(int l,int r){
//	cout<<l<<' '<<r<<endl;
	for(ri i=l;i<=r;i++){
		vis[qry[i].u]=1;
		vis[qry[i].v]=1;
	}
	pnt.clear();
	for(ri i=1;i<=n;i++){
		if(vis[i])pnt.emplace_back(i);
	}
	for(ri i=0;i<pnt.size();i++){
		vis[pnt[i]]=i+1;
	}
	memset(nxt,0,sizeof(nxt));
	memset(head,0,sizeof(head));
	memset(d,0,sizeof(d));
	cnt=0;
	for(ri i=0;i<edge.size();i++){
		if(tongxing[i]){
			add(edge[i].first,edge[i].second);
		}
	}
	qq.clear();
	Small_G::clear();
	Small_G::n=pnt.size();
	for(ri i=1;i<=n;i++){
		if(d[i]==0){
			qq.push(i);
		}
	} 
	memset(kd,0,sizeof(kd));
	while(!qq.empty()){
		int u=qq.front();qq.pop();
		if(vis[u]){
			for(ri i=0;i<pnt.size();i++){
				if(kd[u]>>i&1){
					Small_G::change(i+1,vis[u]);
				}
			}
			kd[u]=1ll<<vis[u]-1;
		}
		for(ri e=head[u];e;e=nxt[e]){
			int v=to[e];
			kd[v]|=kd[u];
			d[v]--;
			if(d[v]==0){
				qq.push(v);
			}
		}
	}
	for(ri i=l;i<=r;i++){
		if(qry[i].op==1){
			Small_G::change(vis[qry[i].u],vis[qry[i].v]);
			tongxing[qry[i].id]^=1;
		} 
		else {
			cout<<(Small_G::kd(vis[qry[i].u],vis[qry[i].v])?"YES":"NO")<<endl;
		}
	}
	memset(vis,0,sizeof(vis));
}
signed main(){
	ios::sync_with_stdio(0);
	cin>>n>>m>>q;
	for(ri i=1;i<=m;i++){
		int u,v;
		cin>>u>>v;
		edge.emplace_back(mkp(u,v));
	}
	memset(tongxing,1,sizeof(tongxing));
	for(ri i=1;i<=q;i++){
		cin>>qry[i].op;
		if(qry[i].op==1){
			cin>>qry[i].id;
			qry[i].id--;
			qry[i].u=edge[qry[i].id].first;
			qry[i].v=edge[qry[i].id].second;
		}
		else{
			cin>>qry[i].u>>qry[i].v;
		}
	}
	for(ri i=1;i<=q/B;i++){
		solve((i-1)*B+1,i*B);
	}
	if(q%B)solve(q/B*B+1,q);
	return 0;
}
/*
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
*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 6660kb

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: 5307ms
memory: 7888kb

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: 2787ms
memory: 7944kb

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 25425th lines differ - expected: 'NO', found: 'YOUDIE'