結果

問題 No.30 たこやき工場
ユーザー h_nosonh_noson
提出日時 2016-03-24 18:49:57
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 3 ms / 5,000 ms
コード長 978 bytes
コンパイル時間 1,109 ms
コンパイル使用メモリ 65,400 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-23 05:17:31
合計ジャッジ時間 1,374 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,376 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 1 ms
4,376 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
権限があれば一括ダウンロードができます

ソースコード

diff #

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

#define RREP(i,s,e) for (i = s; i >= e; i--)
#define rrep(i,n) RREP(i,n,0)
#define REP(i,s,e) for (i = s; i < e; i++)
#define rep(i,n) REP(i,0,n)
#define INF 100000000

typedef long long ll;

vector<pair<unsigned int,int>> e[1500];
unsigned int s[100];
int n;
bool root[101];

unsigned int dfs(int x) {
    if (x == n)
        return s[x] = 1;
    else if (s[x] > 0)
        return s[x];
    else {
        for (auto p : e[x]) {
            s[x] += p.first*dfs(p.second);
            root[p.second] = false;
        }
        root[x] = true;
        return s[x];
    }
}

int main() {
    int i, m;
    cin >> n >> m;
    rep (i,m) {
        int p, q, r;
        cin >> p >> q >> r;
        e[p].push_back(make_pair(q,r));
    }
    rep (i,n)
        dfs(i);
    REP (i,1,n) {
        if (root[i])
            cout << s[i] << endl;
        else
            cout << 0 << endl;
    }
    return 0;
}
0