topo样例没过求调
  • 板块P2712 摄像头
  • 楼主lmy_2011
  • 当前回复1
  • 已保存回复1
  • 发布时间2023/12/18 19:01
  • 上次更新2023/12/18 21:17:55
查看原帖
topo样例没过求调
662413
lmy_2011楼主2023/12/18 19:01
#include<bits/stdc++.h>
using namespace std;
vector<int> nbr[205];
int n, in[10005], cnt, w[105];
bool vis[505];
void topo()
{
	queue<int> q;
	for (int i = 1 ; i <= n ; i++)
	{
		if (in[w[i]] == 0)
		{
			q.push(w[i]);
		}
	}
	while (q.empty() == false)
	{
		int cur = q.front();
		q.pop();
		for (int i = 0 ; i < nbr[cur].size() ; i++)
		{
			int nxt = nbr[cur][i];
			in[nxt]--;
			if(in[nxt] == 0 && vis[nxt] == true)
			{
				q.push(nxt);
				vis[nxt] = false;
			}
		}
	}
	return ;
}
int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin >> n;
	for (int i = 1 ; i <= n ; i++)
	{
		int m;
		cin >> w[i] >> m;
		vis[w[i]] = true;
		for (int j = 1 ; j <= m ; j++)
		{
			int opt;
			cin >> opt;
			nbr[w[i]].push_back(opt);
			in[opt]++;
		}
	}
	topo();
	for (int i = 1 ; i <= n ; i++)
	{
		if(in[w[i]] == 0)
		{
			cnt++;
		}
	}
	if (cnt == 0)
	{
		cout << "YES";
	}
	else
	{
		cout << cnt;
	}
	return 0;
}

样例是 22,输出 33。cntcnt 统计摄像头数量,visivis_i 表示一个摄像机有没有被砸。

2023/12/18 19:01
加载中...