結果
| 問題 | No.679 不思議マーケット | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2018-04-27 22:44:09 | 
| 言語 | D (dmd 2.109.1) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 7 ms / 2,000 ms | 
| コード長 | 1,055 bytes | 
| コンパイル時間 | 953 ms | 
| コンパイル使用メモリ | 117,604 KB | 
| 実行使用メモリ | 6,944 KB | 
| 最終ジャッジ日時 | 2024-06-13 00:56:04 | 
| 合計ジャッジ時間 | 1,608 ms | 
| ジャッジサーバーID (参考情報) | judge5 / judge4 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 18 | 
ソースコード
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;
}
            
            
            
        