結果

問題 No.679 不思議マーケット
ユーザー kurenai3110kurenai3110
提出日時 2018-04-27 22:47:11
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 5 ms / 2,000 ms
コード長 771 bytes
コンパイル時間 750 ms
コンパイル使用メモリ 70,964 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-10 06:36:45
合計ジャッジ時間 1,701 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 5 ms
4,376 KB
testcase_04 AC 3 ms
4,380 KB
testcase_05 AC 3 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 3 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
using namespace std;

typedef long long ll;

int main() {
	int n, m; cin >> n >> m;
	
	vector<vector<int>>E(n);

	for (int i = 0; i < m; i++) {
		int g, r; cin >> g >> r;
		g--;
		for (int j = 0; j < r; j++) {
			int h; cin >> h;
			h--;

			E[g].push_back(h);
		}
	}

	vector<char>used(n);
	bool flag = true;
	while (flag) {
		flag = false;
		for (int i = 0; i < n; i++) {
			if (used[i])continue;

			bool sold = true;
			for (int j = 0; sold && j < E[i].size(); j++) {
				if (!used[E[i][j]])sold = false;
			}

			if (sold) {
				flag = true;
				used[i] = true;
			}
		}
	}

	int ans = 0;
	for (int i = 0; i < n; i++)if (used[i])ans++;

	cout << ans << endl;

	return 0;
}
0