70pts WA on #5 #6 #9求条
  • 板块P2712 摄像头
  • 楼主Sine_Func
  • 当前回复0
  • 已保存回复0
  • 发布时间2025/1/26 19:27
  • 上次更新2025/1/26 19:36:13
查看原帖
70pts WA on #5 #6 #9求条
975724
Sine_Func楼主2025/1/26 19:27
#include <bits/stdc++.h>
#define double long double
#define AC return 0
#define pii pair<int,int>
#define fi first
#define se second
#define gc getchar
#define el cout<<"\n"
#define ls (p<<1)
#define rs (p<<1|1)
//#define int long long
using namespace std;
const int N = 510;
int n, p, u, v, d[N], ans, dqkc[N];
vector<int>edge[N];
queue<int>q;
signed main() {
//	freopen("文件名.in","r",stdin);
//	freopen("文件名.out","w",stdout);
//	ios::sync_with_stdio(0);
//	cin.tie(0);
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> u >> p;
		dqkc[u] = 1;
		while (p--) {
			cin >> v;
			edge[u].push_back(v);
			d[v]++;
		}
//		el;
	}
	for (int i = 1; i <= n; i++)
		if (!d[i])
			q.push(i);
	while (!q.empty()) {
		ans++;
		int l = q.front();
//		cout << l << " ";
		q.pop();
		for (auto i : edge[l]) {
			d[i]--;
			if (!d[i])
				if (dqkc[i])
					q.push(i);
		}
	}
//	el;
	if (ans == n)cout << "YES";
	else cout << n - ans;
	AC;
}
//                          _ooOoo_                               //
//                         o8888888o                              //
//                         88" . "88                              //
//                         (| ^_^ |)                              //
//                         O\  =  /O                              //
//                      ____/`---'\____                           //
//                    .'  \\|     |//  `.                         //
//                   /  \\|||  :  |||//  \                        //
//                  /  _||||| -:- |||||-  \                       //
//                  |   | \\\  -  /// |   |                       //
//                  | \_|  ''\---/''  |   |                       //
//                  \  .-\__  `-`  ___/-. /                       //
//                ___`. .'  /--.--\  `. . ___                     //
//              ."" '<  `.___\_<|>_/___.'  >'"".                  //
//            | | :  `- \`.;`\ _ /`;.`/ - ` : | |                 //
//            \  \ `-.   \_ __\ /__ _/   .-` /  /                 //
//      ========`-.____`-.___\_____/___.-`____.-'========         //
//                           `=---='                              //
//      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^        //
//           佛祖保佑       永不宕机     永无BUG                  //
2025/1/26 19:27
加载中...