luogu P2712 摄像头

题目传送门:https://www.luogu.org/problemnew/show/P2712



题意:

有n个摄像头,每一个摄像头可以拍到一定范围内的东西,每一个东西上有可能有摄像头。现在你需要知道最少有多少个摄像头不会被拍到。注意:当一个摄像头不会被派到时,你可以将它砸掉,它所拍到的地方都不会被它拍到了。



思路:

拓扑排序裸题。



代码:

#include<cstdio>
#include<queue>
#include<algorithm>
using namespace std;
queue<int> f;
	int n,len=0,ans;
	int last[510],du[510];
	bool bz[510];
	struct node{int x,y,next;} a[10010];
void ins(int x,int y)
{
	a[++len].x=x;a[len].y=y;a[len].next=last[x];last[x]=len;
}
int main()
{
	int x,y,t,ma=0;
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%d %d",&x,&t);
		bz[x]=true;
		ma=max(ma,x);
		for(int j=1;j<=t;j++)
		{
			scanf("%d",&y);
			ins(x,y);
			du[y]++;
		}
	}
	for(int i=1;i<=ma;i++)
		if(!du[i]&&bz[i]) f.push(i);
	ans=n;
	while(!f.empty())
	{
		int x=f.front();
		f.pop();
		for(int i=last[x];i;i=a[i].next)
		{
			int y=a[i].y;
			du[y]--;
			if(!du[y]&&bz[y]) f.push(y);
		}
		ans--;
	}
	if(!ans) printf("YES"); else printf("%d",ans);
}

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值