CF1548A.Web of Lies

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

When you play the game of thrones, you win, or you die. There is no middle ground.

Cersei Lannister, A Game of Thrones by George R. R. Martin

There are nn nobles, numbered from 11 to nn . Noble ii has a power of ii . There are also mm "friendships". A friendship between nobles aa and bb is always mutual.

A noble is defined to be vulnerable if both of the following conditions are satisfied:

  • the noble has at least one friend, and
  • all of that noble's friends have a higher power.

You will have to process the following three types of queries.

  1. Add a friendship between nobles uu and vv .
  2. Remove a friendship between nobles uu and vv .
  3. Calculate the answer to the following process.

The process: all vulnerable nobles are simultaneously killed, and all their friendships end. Then, it is possible that new nobles become vulnerable. The process repeats itself until no nobles are vulnerable. It can be proven that the process will end in finite time. After the process is complete, you need to calculate the number of remaining nobles.

Note that the results of the process are not carried over between queries, that is, every process starts with all nobles being alive!

输入格式

The first line contains the integers nn and mm ( 1n21051 \le n \le 2\cdot 10^5 , 0m21050 \le m \le 2\cdot 10^5 ) — the number of nobles and number of original friendships respectively.

The next mm lines each contain the integers uu and vv ( 1u,vn1 \le u,v \le n , uvu \ne v ), describing a friendship. No friendship is listed twice.

The next line contains the integer qq ( 1q21051 \le q \le 2\cdot {10}^{5} ) — the number of queries.

The next qq lines contain the queries themselves, each query has one of the following three formats.

  • 11 uu vv ( 1u,vn1 \le u,v \le n , uvu \ne v ) — add a friendship between uu and vv . It is guaranteed that uu and vv are not friends at this moment.
  • 22 uu vv ( 1u,vn1 \le u,v \le n , uvu \ne v ) — remove a friendship between uu and vv . It is guaranteed that uu and vv are friends at this moment.
  • 33 — print the answer to the process described in the statement.

输出格式

For each type 33 query print one integer to a new line. It is guaranteed that there will be at least one type 33 query.

输入输出样例

  • 输入#1

    4 3
    2 1
    1 3
    3 4
    4
    3
    1 2 3
    2 3 1
    3

    输出#1

    2
    1
  • 输入#2

    4 3
    2 3
    3 4
    4 1
    1
    3

    输出#2

    1

说明/提示

Consider the first example. In the first type 3 query, we have the diagram below.

In the first round of the process, noble 11 is weaker than all of his friends ( 22 and 33 ), and is thus killed. No other noble is vulnerable in round 1. In round 2, noble 33 is weaker than his only friend, noble 44 , and is therefore killed. At this point, the process ends, and the answer is 22 .

In the second type 3 query, the only surviving noble is 44 .

The second example consists of only one type 33 query. In the first round, two nobles are killed, and in the second round, one noble is killed. The final answer is 11 , since only one noble survives.

首页