結果

問題 No.679 不思議マーケット
コンテスト
ユーザー V_Melville
提出日時 2026-11-19 22:19:14
言語 C++23
(gcc 15.3.0 + boost 1.92.0 + ACL)
コンパイル:
g++-15 -O2 -fplugin=/usr/lib/yukicoder/noavx512-gcc15.so -lm -std=c++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 2 ms / 2,000 ms
+ 341µs
コード長 882 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 2,394 ms
コンパイル使用メモリ 349,380 KB
実行使用メモリ 9,904 KB
最終ジャッジ日時 2026-11-19 22:19:19
合計ジャッジ時間 4,544 ms
ジャッジサーバーID
(参考情報)
judge4_0 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 18
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)

using namespace std;

int main() {
    cin.tie(nullptr) -> sync_with_stdio(false);
    
    int n, m;
    cin >> n >> m;

    vector<int> cnt(n);
    vector<bool> has(n);
    vector<vector<int>> to(n);

    while (m--) {
        int g, r;
        cin >> g >> r;
        --g;

        has[g] = true;
        cnt[g] = r;

        while (r--) {
            int h;
            cin >> h;
            --h;
            to[h].push_back(g);
        }
    }
    
    int ans = 0;
    queue<int> q;

    rep(i, n) if (!has[i]) {
        q.push(i);
        ans++;
    }

    while (q.size()) {
        int v = q.front(); q.pop();

        for (int u : to[v]) {
            if (--cnt[u] == 0) {
                q.push(u);
                ans++;
            }
        }
    }

    cout << ans << '\n';
    
    return 0;
}
0