zoukankan      html  css  js  c++  java
  • Codeforces Round #736 (Div. 2)C. Web of Lies(结论)

    题目大意:

    一张图,若于a相连点的序号都比a大则a可删除。
    q次询问
    od=1 x,y 给xy连边
    od=2 x,y 给xy删边
    od=3 询问几个点没被删除

    题解:发现有连锁反应,只要某点所连接的点中有序号比它大的就一定会被删除。

    #include<bits/stdc++.h>
    using namespace std;
    
    const int N=2e5+8;
    
    int n,m;
    int q;
    int rd[N];
    
    int main()
    {
    	scanf("%d%d",&n,&m);
    	for(int i=1;i<=m;i++)
    	{
    		int x,y;
    		scanf("%d%d",&x,&y);
    		if(x>y) rd[y]++;
    		else rd[x]++;
    	}
    	int ans=0;
    	for(int i=1;i<=n;i++)
    	{
    		if(!rd[i]) ans++;
    	}
    	scanf("%d",&q);
    	while(q--)
    	{
    		int od;
    		scanf("%d",&od);
    		if(od==1)
    		{
    			int x,y;
    			scanf("%d%d",&x,&y);
    			if(x>y)
    			{
    				rd[y]++;
    				if(rd[y]==1) ans--;
    			}else
    			{
    				rd[x]++;
    				if(rd[x]==1) ans--;
    			}
    		}
    		if(od==2)
    		{
    			int x,y;
    			scanf("%d%d",&x,&y);
    			if(x>y)
    			{
    				rd[y]--;
    				if(rd[y]==0) ans++;
    			}else
    			{
    				rd[x]--;
    				if(rd[x]==0) ans++; 
    			}
    		}
    		if(od==3) cout<<ans<<endl;
    	}
    	return 0;
    }
    
  • 相关阅读:
    poj2774
    GDOI2012 字符串
    poj3261
    poj1743
    bzoj 2565 manacher
    归档-ios
    学习
    ViewPager动态加载、删除页面
    android:ScrollView嵌套ListView的问题
    Android学习笔记进阶之在图片上涂鸦(能清屏)
  • 原文地址:https://www.cnblogs.com/zzyh/p/15253018.html
Copyright © 2011-2022 走看看