結果
問題 | No.679 不思議マーケット |
ユーザー | nebukuro09 |
提出日時 | 2018-04-27 22:44:09 |
言語 | D (dmd 2.107.1) |
結果 |
AC
|
実行時間 | 8 ms / 2,000 ms |
コード長 | 1,055 bytes |
コンパイル時間 | 886 ms |
コンパイル使用メモリ | 102,368 KB |
実行使用メモリ | 4,388 KB |
最終ジャッジ日時 | 2023-09-03 20:04:41 |
合計ジャッジ時間 | 1,862 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge15 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
4,388 KB |
testcase_01 | AC | 2 ms
4,380 KB |
testcase_02 | AC | 1 ms
4,380 KB |
testcase_03 | AC | 8 ms
4,380 KB |
testcase_04 | AC | 4 ms
4,380 KB |
testcase_05 | AC | 5 ms
4,376 KB |
testcase_06 | AC | 2 ms
4,376 KB |
testcase_07 | AC | 2 ms
4,380 KB |
testcase_08 | AC | 4 ms
4,380 KB |
testcase_09 | AC | 2 ms
4,376 KB |
testcase_10 | AC | 2 ms
4,380 KB |
testcase_11 | AC | 2 ms
4,380 KB |
testcase_12 | AC | 2 ms
4,380 KB |
testcase_13 | AC | 3 ms
4,384 KB |
testcase_14 | AC | 3 ms
4,380 KB |
testcase_15 | AC | 3 ms
4,380 KB |
testcase_16 | AC | 1 ms
4,376 KB |
testcase_17 | AC | 1 ms
4,384 KB |
ソースコード
import std.stdio, std.array, std.string, std.conv, std.algorithm; import std.typecons, std.range, std.random, std.math, std.container; import std.numeric, std.bigint, core.bitop, std.bitmanip; void main() { auto s = readln.split.map!(to!int); auto N = s[0]; auto M = s[1]; auto G = new int[][](N); auto H = new int[][](N); foreach (_; 0..M) { s = readln.split.map!(to!int); auto g = s[0] - 1; auto r = s[1]; auto hh = readln.split.map!(to!int).array; foreach (h; hh) G[g] ~= h-1, H[h-1] ~= g; } auto D = new int[](N); foreach (i; 0..N) D[i] = G[i].length.to!int; int p = 0; auto stack = new int[](N); foreach (i; 0..N) if (D[i] == 0) stack[p++] = i; auto used = new bool[](N); int ans = 0; while (p > 0) { auto n = stack[--p]; if (used[n]) continue; ans += 1; used[n] = true; foreach (m; H[n]) { D[m] -= 1; if (D[m] == 0 && !used[m]) stack[p++] = m; } } ans.writeln; }