比赛 CSP2022提高组 评测结果 AAAAAAAAEEEEEEEEEEEE
题目名称 星战 最终得分 40
用户昵称 该账号已注销 运行时间 5.605 s
代码语言 C++ 内存使用 12.04 MiB
提交时间 2022-10-30 10:30:35
显示代码纯文本
#include <bits/stdc++.h>
using namespace std;

struct edge {
	int t, n;
} e[500100], e2[500100];
int n, m, hd[500100], cnt = 0, q, hd2[500100], cnt2 = 0;

int cd[500100] = {0};

bool des[1010][1010] = {0};

void add(int x, int y) {
	e[++cnt].t = y;
	e[cnt].n = hd[x];
	hd[x] = cnt;
	e2[++cnt2].t = x;
	e2[cnt].n = hd2[y];
	hd2[y] = cnt2;
}
int main() {
	freopen("csp2022_galaxy.in", "r", stdin);
	freopen("csp2022_galaxy.out", "w", stdout);
	cin >> n >> m;
	for (int i = 1; i <= m; i++) {
		int u, v;
		cin >> u >> v;
		cd[u]++;
		add(u, v);
	}
	bool a = 0;
	cin >> q;
	for (int i = 1; i <= q; i++) {
		int t;
		cin >> t;
		if (t == 1) {
			int x, y;
			cin >> x >> y;
			cd[x]--;
			des[x][y] = 1;
		}
		if (t == 2) {
			int x;
			cin >> x;
			for (int i = hd2[x]; i; i = e2[i].n) {
				int ver = e2[i].t;
				if (des[ver][x] == 0) {
					des[ver][x] = 1;
					cd[ver]--;
				}
			}
		}
		if (t == 3) {
			int x, y;
			cin >> x >> y;
			des[x][y] = 0;
			cd[x]++;
		}
		if (t == 4) {
			int x;
			cin >> x;
			for (int i = hd2[x]; i; i = e2[i].n) {
				int ver = e2[i].t;
				if (des[ver][x] == 1) {
					des[ver][x] = 0;
					cd[ver]++;
				}
			}
		}
		bool yn = 0;
		for (int j = 1; j <= n; j++) {
			if (cd[j] != 1) {
				cout << "NO" << endl;
				yn = 1;
				break;
			}
		}
		if (yn == 0)
			cout << "YES" << endl;
	}
	return 0;
}