結果

問題 No.30 たこやき工場
ユーザー ふーらくたるふーらくたる
提出日時 2016-07-06 13:14:21
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 3 ms / 5,000 ms
コード長 1,081 bytes
コンパイル時間 449 ms
コンパイル使用メモリ 61,752 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-23 05:17:47
合計ジャッジ時間 1,299 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,376 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,384 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 1 ms
4,384 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘void Solve()’:
main.cpp:36:55: warning: narrowing conversion of ‘Q[i]’ from ‘ll’ {aka ‘long long int’} to ‘int’ inside { } [-Wnarrowing]
         graph[P[i] - 1].push_back((Edge){R[i] - 1, Q[i]});
                                                    ~~~^

ソースコード

diff #

#include <iostream>
#include <vector>
using namespace std;

struct Edge {
    int to, cost;
};

typedef long long ll;

const int kMAX_N = 110;
const int kMAX_M = 1510;
ll magnifications[kMAX_N];

int N, M;
vector<Edge> graph[kMAX_N];
int deg_minus[kMAX_N];

int P[kMAX_M], R[kMAX_M];
ll Q[kMAX_M];

// 倍率を返す
ll DFS(int node) {
    if (magnifications[node] > 0) return magnifications[node];
    if (node == N - 1) return 1;
    ll mag = 0;
    for (int i = 0; i < graph[node].size(); i++) {
        Edge e = graph[node][i];
        mag += DFS(e.to) * e.cost;
    }
    return magnifications[node] = mag;
}

void Solve() {
    for (int i = 0; i < M; i++) {
        graph[P[i] - 1].push_back((Edge){R[i] - 1, Q[i]});
        deg_minus[R[i] - 1]++;
    }

    for (int i = 0; i < N - 1; i++) {
        if (deg_minus[i] == 0) {
            cout << DFS(i) * 1 << endl;
        } else {
            cout << 0 << endl;
        }
    }
}

int main() {
    cin >> N >> M;

    for (int i = 0; i < M; i++) {
        cin >> P[i] >> Q[i] >> R[i];
    }

    Solve();

    return 0;
}
0