結果

問題 No.30 たこやき工場
ユーザー xuzijian629xuzijian629
提出日時 2018-10-31 08:37:16
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 3 ms / 5,000 ms
コード長 1,365 bytes
コンパイル時間 2,194 ms
コンパイル使用メモリ 210,040 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-23 05:20:29
合計ジャッジ時間 3,058 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using i64 = int64_t;
using vi = vector<i64>;
using vvi = vector<vi>;
using ii = pair<int, i64>;

int main() {
    int n, m;
    cin >> n >> m;
    
    vector<set<ii>> ins(n), outs(n);
    for (int i = 0; i < m; i++) {
        int a, w, b;
        cin >> a >> w >> b;
        a--;
        b--;
        ins[b].insert(ii(a, w));
        outs[a].insert(ii(b, w));
    }

    vi needs(n), visited(n);
    needs.back() = 1;

    while (1) {
        int change = 0;
        for (int i = 0; i < n; i++) {
            if (visited[i]) continue;
            if (outs[i].empty()) {
                // cout << "Found empty: " << i << endl;
                visited[i] = 1;
                // if (needs[i] == 0) continue;
                for (auto& e: ins[i]) {
                    int k = e.first;
                    // cout << "node " << k << " is going to " << i << " with cost " << e.second << endl;  
                    needs[k] += needs[i] * e.second;
                    // cout << "need[k] has updated: " << needs[k] << endl;
                    outs[k].erase(ii(i, e.second));
                }
                change = 1;
            }
        }
        if (!change) break;
    }
    for (int i = 0; i < n - 1; i++) {
        // cout << needs[i] << endl;
        cout << (ins[i].empty() ? needs[i] : 0) << endl;
    }
}  
0