結果

問題 No.679 不思議マーケット
ユーザー kakakakanekokakakakaneko
提出日時 2018-09-18 16:44:25
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 9 ms / 2,000 ms
コード長 1,132 bytes
コンパイル時間 1,859 ms
コンパイル使用メモリ 172,480 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-25 09:50:18
合計ジャッジ時間 2,755 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include "bits/stdc++.h"

using namespace std;
using ll = long long;
using ull = unsigned long long;

typedef pair< long long, long long > P;
typedef pair< long long, P > PP;
typedef pair< P, P > PPP;

const long long MOD = 1e9 + 7;
const long long  INF = 5e18;
const double DINF = 5e14;
const double eps = 1e-10;
const int di[4] = { 1,0,-1,0 }, dj[4] = { 0,1,0,-1 };

#define fr first
#define sc second
#define pb push_back
#define eb emplace_back
#define ALL(x) (x).begin(),(x).end()

int n, m, h, g, r, ans, rr[510];
map<int, vector<int>>mp;
bool b[510];

int main() {
	cin >> n >> m;
	for (int i = 0;i < m;i++) {
		cin >> g >> r;
		rr[g] = r;
		for (int j = 0;j < r;j++) {
			cin >> h;
			mp[g].eb(h);
		}
	}
	while (true) {
		bool fl = 0;
		for (int i = 1;i <= n;i++) {
			if (b[i])continue;
			if (mp[i].size() == 0) {
				ans++;
				b[i] = 1;
				fl = 1;
			}
			else {
				bool f = 0;
				for (int j = 0;j < rr[i];j++) {
					if (!b[mp[i][j]]) {
						f = 1;
						break;
					}
				}
				if (!f) {
					ans++;
					b[i] = 1;
					fl = 1;
				}
			}
		}
		if (!fl) {
			cout << ans << endl;
			return 0;
		}
	}
	return 0;
}
0