結果

問題 No.30 たこやき工場
ユーザー なおなお
提出日時 2014-09-25 22:47:37
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 1,145 bytes
コンパイル時間 1,825 ms
コンパイル使用メモリ 67,024 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-23 05:13:25
合計ジャッジ時間 1,702 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 2 ms
4,380 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 <cstdlib>
#include <iostream>
#include <vector>
#include <set>
using namespace std;

const int MAXN = 100;
typedef unsigned long long ull;

int N,M;
int matrix[MAXN][MAXN];
bool flg[MAXN];
ull memo[MAXN][MAXN];
ull item[MAXN];
set<int> s;

void dfs(int i, ull n, ull *out){
    if(s.count(i)){ cout << "矛盾しています。" << endl; exit(1); }
    s.insert(i);
    //cout << "i = " << i << ", n = " << n << endl;

    if(!flg[i]){
        bool f = false;
        for(int j = 0; j < N; j++){
            if(matrix[i][j] > 0){
                dfs(j, matrix[i][j], memo[i]);
                f = true;
            }
        }
        if(!f){
            memo[i][i] = 1;
        }
        flg[i] = true;
    }
    for(int j = 0; j < N; j++){
        out[j] += memo[i][j] * n;
    }

    s.erase(i);
}

int main(){
    cin >> N >> M;
    for(int i = 0; i < M; i++){
        int P,Q,R;
        cin >> P >> Q >> R;
        if(matrix[R-1][P-1]){ cout << "不正データ" << endl; exit(1); }
        matrix[R-1][P-1] = Q;
    }
    dfs(N-1, 1, item);
    for(int i = 0; i < N-1; i++){
        cout << item[i] << endl;
    }
    return 0;
}
0