結果

問題 No.30 たこやき工場
コンテスト
ユーザー himueu
提出日時 2026-10-17 16:36:35
言語 C++23(gcc16)
(gcc 16.2.0 + boost 1.92.0 + ACL)
コンパイル:
g++-16 -O2 -lm -std=c++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 2 ms / 5,000 ms
+ 175µs
コード長 695 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,799 ms
コンパイル使用メモリ 195,224 KB
実行使用メモリ 6,400 KB
最終ジャッジ日時 2026-10-17 16:36:40
合計ジャッジ時間 3,846 ms
ジャッジサーバーID
(参考情報)
judge4_0 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 11
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <atcoder/scc>
#include <iostream>
#include <utility>
#include <vector>

int main() {
    using namespace std;
    int n, m;
    cin >> n >> m;
    vector<bool> buy(n, true);
    vector<vector<pair<int, int>>> g(n);
    atcoder::scc_graph scc(n);
    while (m--) {
        int p, q, r;
        cin >> p >> q >> r;
        g[r - 1].emplace_back(p - 1, q);
        scc.add_edge(r - 1, p - 1);
        buy[r - 1] = false;
    }

    vector<int> need(n, 0);
    need[n - 1] = 1;
    for (auto group : scc.scc()) {
        int v = group[0];
        for (auto [nv, w] : g[v]) { need[nv] += need[v] * w; }
    }

    for (int v = 0; v < n - 1; v++) { cout << (buy[v] ? need[v] : 0) << endl; }
}
0