QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#410973#4000. Dynamic ReachabilityGTAHWA 524ms9860kbC++143.2kb2024-05-14 19:10:382024-05-14 19:10:39

Judging History

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

  • [2024-05-14 19:10:39]
  • 评测
  • 测评结果:WA
  • 用时:524ms
  • 内存:9860kb
  • [2024-05-14 19:10:38]
  • 提交

answer

#include<iostream>
#include<cstring>
#include<utility>
#include<queue>
#include<algorithm>
#include<map> 
using namespace std;
using ull = unsigned long long;
using ll = long long;
using pii = pair<int,int>;
const int N = 5e4 + 5, M = 1e5 + 5, Q = 1e5 + 5, LEN = 32; 
struct question{
	int opt, u, v;
}q[Q];
int n, m, q_cnt;
int head[N], from[M], to[M], nxt[M], col[M], cnt_edge;
inline void add(int u,int v) {
	nxt[++cnt_edge] = head[u];
	from[cnt_edge] = u;
	to[cnt_edge] = v;
	col[cnt_edge] = 1;
	head[u] = cnt_edge;
}
namespace slove{
	map<pii,int> mp;
	int lsh[100], has[N], cnt;
	int cut[M], vis[N];
	ull f[N], end[N];
	int h[N], nx[M], t[M], c[M], cnt_edge;
	int el[M];
	question qq[100];
	int cc;
	queue<int> que,que_np;
	void add(int u,int v) {
		nx[++cnt_edge] = h[u];
		t[cnt_edge] = v;
		h[u] = cnt_edge;
		c[cnt_edge] = 1;
	}
	void prepare(int start) {
		mp.clear();
		cnt = 0, cc = 0, cnt_edge = 0;
		memset(has,0,sizeof(has));
		memset(lsh,0,sizeof(lsh));
		memset(cut,0,sizeof(cut));
		memset(vis,0,sizeof(vis));
		memset(f,0,sizeof(f));
		memset(end,0,sizeof(end));
		memset(el,0,sizeof(el));
		memset(h,0,sizeof(h));
		memset(c,0,sizeof(c));
		memset(nx,0,sizeof(nx));
		memset(t,0,sizeof(t));
		for(int i=start;i<=q_cnt&&i<start+LEN;++i) {
			qq[++cc] = q[i];
			if(q[i].opt == 1) {
				lsh[++cnt] = from[q[i].u];
				lsh[++cnt] = to[q[i].u];
				
				cut[q[i].u] = 1;
				
				if(mp[make_pair(from[q[i].u],to[q[i].u])] == 0 && (mp[make_pair(from[q[i].u],to[q[i].u])] = 1)) {
					add(from[q[i].u],to[q[i].u]);
					c[cnt_edge] = col[q[i].u];
					el[q[i].u] = cnt_edge;
				}
			} else {
				lsh[++cnt] = q[i].u;
				lsh[++cnt] = q[i].v;
			}
		}
		sort(lsh+1,lsh+cnt+1);
		cnt = unique(lsh+1,lsh+cnt+1) - lsh - 1;
		for(int i=1;i<=cnt;++i) has[lsh[i]] = i;
		return;
	}
	void bfs(int s) {
		que.push(s);
		vis[s] = 1;
		while(!que.empty()) {
			int u = que.front();
			que.pop();
			for(int e = head[u]; e; e=nxt[e]) {
				if(cut[e] == 1 || col[e] == 0) continue;
				int v = to[e];
				if(has[v]) end[v] |= f[u];
				else if(!vis[v]) {
					f[v] |= f[u];
					vis[v] = 1;
					que.push(v);
					que_np.push(v);
				}
			}
		}
		return;
	} 
	int dfs(int u, int tt) {
		if(u == tt) return 1;
		for(int e=h[u];e;e=nx[e]) {
			if(c[e] == 1) {
				if(dfs(t[e],tt)) return 1;
			}
		}
		return 0;
	} 
	void slove() {
		for(int i=1;i<=cnt;++i) {
			f[lsh[i]] |= (1ull<<(has[lsh[i]] - 1)), vis[lsh[i]] = 1; 
		}
		for(int i=1;i<=cnt;++i){
			bfs(lsh[i]);
			while(!que_np.empty()) vis[que_np.front()] = 0, que_np.pop();
		} 
		for(int i=1;i<=cnt;++i) {
			for(int j=0;j<cnt;++j) {
				if(i == j+1) continue;
				if((end[lsh[i]]>>j)&1) add(lsh[j+1],lsh[i]); 
			}
		}
		for(int i=1;i<=cc;++i) {
			if(qq[i].opt == 1) {
				c[el[qq[i].u]] ^= 1;
			}  else {
				if(dfs(qq[i].u,qq[i].v)) cout<<"YES"<<endl;
				else cout<<"NO"<<endl;
			}
		}
		return;
	}
}
int main() {
	ios::sync_with_stdio(0);
	cin>>n>>m>>q_cnt;
	for(int i=1,u,v;i<=m;++i) {
		cin>>u>>v;
		add(u,v);
	} 
	for(int i=1;i<=q_cnt;++i) {
		cin>>q[i].opt>>q[i].u;
		if(q[i].opt == 2) cin>>q[i].v;
	}
	for(int i=1;i<=q_cnt;i+=LEN) {
		slove::prepare(i);
		slove::slove();
	}
	return 0;
} 

詳細信息

Test #1:

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

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: 524ms
memory: 9860kb

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