結果

問題 No.30 たこやき工場
ユーザー takerous7takerous7
提出日時 2020-03-15 14:58:42
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 4,720 ms / 5,000 ms
コード長 1,204 bytes
コンパイル時間 1,664 ms
コンパイル使用メモリ 172,552 KB
実行使用メモリ 4,504 KB
最終ジャッジ日時 2023-08-23 05:22:23
合計ジャッジ時間 7,092 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define  rep(i, n) for(int i = 0; i < n; i++) 
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  INF 1LL << 60
typedef long long int LL;
typedef long long int ll;
#define pll pair<ll, ll>
#define F first
#define S second
const int MOD = 1000000007;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }
//sort(all(x))とするとソートできるよ
// 10^x は pow(10,(x)) 
// 任意のlogは 対数の底の変換を使う    log(N) / log(任意の底)

int N,M;
vector<vector<pll>> G;
vector<LL> buy;

void dfs(int n,LL sum){
    if(G[n].size() == 0)buy[n] += sum;
    else{
        for(auto t : G[n]){
            int to = t.F;
            LL vl = t.S;
            dfs(to,sum * vl);
        }
    }
}

int main(){
    cin >> N >> M;
    G.resize(N);
    buy.resize(N);

    rep(i,M){
        LL P,Q,R;cin >> P >> Q >> R;
        P--;R--;
        G[R].push_back({P,Q});
    }

    dfs(N-1,1);
    rep(i,N-1)cout << buy[i] << endl;
}
0