A14436 | Web of Lies
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
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 $n$ nobles, numbered from $1$ to $n$ . Noble $i$ has a power of $i$ . There are also $m$ "friendships". A friendship between nobles $a$ and $b$ 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 $u$ and $v$ .
2. Remove a friendship between nobles $u$ and $v$ .
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!
Cersei Lannister, A Game of Thrones by George R. R. Martin
There are $n$ nobles, numbered from $1$ to $n$ . Noble $i$ has a power of $i$ . There are also $m$ "friendships". A friendship between nobles $a$ and $b$ 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 $u$ and $v$ .
2. Remove a friendship between nobles $u$ and $v$ .
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 $n$ and $m$ ( $1 \le n \le 2\cdot 10^5$ , $0 \le m \le 2\cdot 10^5$ ) — the number of nobles and number of original friendships respectively.
The next $m$ lines each contain the integers $u$ and $v$ ( $1 \le u,v \le n$ , $u \ne v$ ), describing a friendship. No friendship is listed twice.
The next line contains the integer $q$ ( $1 \le q \le 2\cdot {10}^{5}$ ) — the number of queries.
The next $q$ lines contain the queries themselves, each query has one of the following three formats.
- $1$ $u$ $v$ ( $1 \le u,v \le n$ , $u \ne v$ ) — add a friendship between $u$ and $v$ . It is guaranteed that $u$ and $v$ are not friends at this moment.
- $2$ $u$ $v$ ( $1 \le u,v \le n$ , $u \ne v$ ) — remove a friendship between $u$ and $v$ . It is guaranteed that $u$ and $v$ are friends at this moment.
- $3$ — print the answer to the process described in the statement.
The next $m$ lines each contain the integers $u$ and $v$ ( $1 \le u,v \le n$ , $u \ne v$ ), describing a friendship. No friendship is listed twice.
The next line contains the integer $q$ ( $1 \le q \le 2\cdot {10}^{5}$ ) — the number of queries.
The next $q$ lines contain the queries themselves, each query has one of the following three formats.
- $1$ $u$ $v$ ( $1 \le u,v \le n$ , $u \ne v$ ) — add a friendship between $u$ and $v$ . It is guaranteed that $u$ and $v$ are not friends at this moment.
- $2$ $u$ $v$ ( $1 \le u,v \le n$ , $u \ne v$ ) — remove a friendship between $u$ and $v$ . It is guaranteed that $u$ and $v$ are friends at this moment.
- $3$ — print the answer to the process described in the statement.
输出格式
For each type $3$ query print one integer to a new line. It is guaranteed that there will be at least one type $3$ 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 $1$ is weaker than all of his friends ( $2$ and $3$ ), and is thus killed. No other noble is vulnerable in round 1. In round 2, noble $3$ is weaker than his only friend, noble $4$ , and is therefore killed. At this point, the process ends, and the answer is $2$ .
In the second type 3 query, the only surviving noble is $4$ .
The second example consists of only one type $3$ query. In the first round, two nobles are killed, and in the second round, one noble is killed. The final answer is $1$ , since only one noble survives.

In the first round of the process, noble $1$ is weaker than all of his friends ( $2$ and $3$ ), and is thus killed. No other noble is vulnerable in round 1. In round 2, noble $3$ is weaker than his only friend, noble $4$ , and is therefore killed. At this point, the process ends, and the answer is $2$ .
In the second type 3 query, the only surviving noble is $4$ .
The second example consists of only one type $3$ query. In the first round, two nobles are killed, and in the second round, one noble is killed. The final answer is $1$ , since only one noble survives.

C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted