結果

問題 No.30 たこやき工場
ユーザー tottoripapertottoripaper
提出日時 2014-11-19 23:27:57
言語 C++11
(gcc 11.4.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 973 bytes
コンパイル時間 382 ms
コンパイル使用メモリ 50,844 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-30 21:54:17
合計ジャッジ時間 2,206 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <cstdio>
#include <algorithm>
#include <vector>
#include <queue>

typedef long long ll;

struct Edge{
    int to;
    ll cost;
};

int N, M;
std::vector<Edge> G[101], rG[101];
std::vector<int> order;
bool used[101];
ll d[101];

void dfs(int u){
    used[u] = true;

    for(auto e : G[u]){
        if(!used[e.to]){
            dfs(e.to);
        }
    }

    order.push_back(u);
}

int main(){
    scanf("%d %d", &N, &M);

    for(int i=0;i<M;i++){
        int p, r;
        ll q;
        scanf("%d %lld %d", &p, &q, &r);
        
        G[r].push_back({p, q});
        rG[p].push_back({r, q});
    }

    dfs(N);
    
    d[N] = 1ll;
    for(int i=N-2;i>=0;i--){
        for(auto e : rG[order[i]]){
            d[order[i]] += d[e.to] * e.cost;
        }
    }

    for(int i=1;i<N;i++){
        if(G[i].empty()){
            printf("%lld\n", d[i]);
        }else{
            puts("0");
        }
    }
}
0