A. Web of Lies- Codeforces Round #736 (Div. 1)

Problem - 1548A - Codeforces

A. Web of Lies

time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

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!

Input

The first line contains the integers nn and mm (1≤n≤2⋅1051≤n≤2⋅105, 0≤m≤2⋅1050≤m≤2⋅105) — the number of nobles and number of original friendships respectively.

The next mm lines each contain the integers uu and vv (1≤u,v≤n1≤u,v≤n, u≠vu≠v), describing a friendship. No friendship is listed twice.

The next line contains the integer qq (1≤q≤2⋅1051≤q≤2⋅105) — the number of queries.

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

  • 11 uu vv (1≤u,v≤n1≤u,v≤n, u≠vu≠v) — add a friendship between uu and vv. It is guaranteed that uu and vv are not friends at this moment.
  • 22 uu vv (1≤u,v≤n1≤u,v≤n, u≠vu≠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.

Output

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.

Examples

input

Copy

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

output

Copy

2
1

input

Copy

4 3
2 3
3 4
4 1
1
3

output

Copy

1

Note

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.

---------------------------------------------------------------------------------------------------------------------------------首先,3操作是不停进行的,也就是说,如果一个点,它连接了比它强的,那么它一定会在操作3中死亡,当连接的没有比它强的时候,它就永远存活。 如果一个点新加一条边,正好指向比它强的,那么很可怜,它必定会在3操作中被除掉,如果新删除一条边,正好删除了仅有的比它强的那条边,那么很幸运,3操作它不会被杀

所以,只需要统计每个点连接了多少比它强的就行,

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<algorithm>
#include<cmath>
# include<map>
# include<iomanip>

using namespace std;
typedef long long int ll;


int out[200000+10];

int main()
{

   //一个人直接朋友如果比它强,那么它必然死掉

   int ans=0;

   int n,t,m;
   cin>>n>>m;
   ans=n;
   while(m--)
   {
       int x,y;
       cin>>x>>y;

       out[min(x,y)]++;

      if(out[min(x,y)]==1)
        ans--;


   }


   cin>>t;

   while(t--)
   {
       int x,y;

       cin>>x;

       if(x==1)
       {
           cin>>x>>y;
           out[min(x,y)]++;
           if(out[min(x,y)]==1)
            ans--;

       }
       else if(x==2)
       {
           cin>>x>>y;

           out[min(x,y)]--;

           if(out[min(x,y)]==0)
            ans++;
       }
       else
       {
           cout<<ans<<'\n';
       }
   }




    return 0;
}

  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

qinsanma and Code

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值