星战 50 分。
/*
* @Author: crab-in-the-northeast
* @Date: 2022-10-31 04:06:42
* @Last Modified by: crab-in-the-northeast
* @Last Modified time: 2022-10-31 04:30:00
*/
#include <bits/stdc++.h>
inline int read() {
int x = 0;
bool flag = true;
char ch = getchar();
while (!isdigit(ch)) {
if (ch == '-')
flag = false;
ch = getchar();
}
while (isdigit(ch)) {
x = (x << 1) + (x << 3) + ch - '0';
ch = getchar();
}
if(flag)
return x;
return ~(x - 1);
}
const int maxn = (int)5e5 + 5;
int oud[maxn];
// oud 是出度
typedef std :: pair <int, int> pii;
std :: vector <pii> R[maxn];
// R 是一个反图,R[v] 存的是连向 v 的边的数据
// pii 中第一个表示边的起点 u,第二个表示是否在激活状态
int main() {
int n = read(), m = read();
while (m--) {
int u = read(), v = read();
++oud[u];
R[v].emplace_back(u, 1);
}
int tot = 0;
for (int u = 1; u <= n; ++u)
if (oud[u] == 1)
++tot;
int q = read();
bool in1to8 = (q <= (int)1e3) && (m <= (int)1e4)
&& (n <= (int)1e3);
while (q--) {
int t = read();
if (t == 1) {
int u = read(), v = read();
if (oud[u] == 1)
--tot;
--oud[u];
if (oud[u] == 1)
++tot;
if (in1to8)
for (pii &e : R[v])
if (e.first == u)
e.second = 0;
} else if (t == 3) {
int u = read(), v = read();
if (oud[u] == 1)
--tot;
++oud[u];
if (oud[u] == 1)
++tot;
if (in1to8)
for (pii &e : R[v])
if (e.first == u)
e.second = 1;
} else if (t == 2) {
int v = read();
for (pii &e : R[v]) {
if (e.second == 0)
continue;
e.second = 0;
int u = e.first;
if (oud[u] == 1)
--tot;
--oud[u];
if (oud[u] == 1)
++tot;
}
} else if (t == 4) {
int v = read();
for (pii &e : R[v]) {
if (e.second == 1)
continue;
e.second = 1;
int u = e.first;
if (oud[u] == 1)
--tot;
++oud[u];
if (oud[u] == 1)
++tot;
}
}
puts(tot == n ? "YES" : "NO");
}
return 0;
}