/* -*- coding: utf-8 -*- * * 3390.cc: No.3390 Public or Private - yukicoder */ #include #include #include #include using namespace std; /* constant */ /* typedef */ using si = set; using misi = map; /* global variables */ /* subroutines */ int countand(si &s0, si &s1) { auto sit0 = s0.begin(), se0 = s0.end(); auto sit1 = s1.begin(), se1 = s1.end(); int cnt = 0; while (sit0 != se0 && sit1 != se1) { if (*sit0 < *sit1) sit0++; else if (*sit0 > *sit1) sit1++; else cnt++, sit0++, sit1++; } return cnt; } /* main */ int main() { int n, m; scanf("%d%d", &n, &m); misi fs; for (int i = 0; i < m; i++) { int u, v; scanf("%d%d", &u, &v); fs[u].insert(v); } si ps; int qn; scanf("%d", &qn); while (qn--) { int qi, ai, bi; scanf("%d%d%d", &qi, &ai, &bi); if (qi == 1) { auto mit = fs.find(ai); if (mit == fs.end()) fs[ai].insert(bi); else { auto &fsa = mit->second; auto sit = fsa.find(bi); if (sit == fsa.end()) fsa.insert(bi); else fsa.erase(sit); } } else { auto sit = ps.find(ai); if (sit == ps.end()) ps.insert(ai); else ps.erase(sit); } int cnt = n - ps.size() - (1 - ps.count(ai)); auto mit = fs.find(ai); if (mit != fs.end()) cnt += countand(mit->second, ps); printf("%d\n", cnt); } return 0; }