結果
問題 |
No.30 たこやき工場
|
ユーザー |
![]() |
提出日時 | 2015-07-21 22:31:30 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,340 bytes |
コンパイル時間 | 1,255 ms |
コンパイル使用メモリ | 165,868 KB |
実行使用メモリ | 13,880 KB |
最終ジャッジ日時 | 2024-07-08 11:38:38 |
合計ジャッジ時間 | 7,791 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 10 TLE * 1 -- * 6 |
ソースコード
#include <bits/stdc++.h> typedef long long ll; typedef unsigned long long ull; #define FOR(i,a,b) for(int (i)=(a);i<(b);i++) #define REP(i,n) FOR(i,0,n) #define RANGE(vec) (vec).begin(),(vec).end() using namespace std; class TakoyakiFactory { public: struct Edge { Edge(int t, ll c) : to(t), cost(c) {} int to; ll cost; }; void solve(void) { int N,M; cin>>N>>M; // 木を逆にたどればよいだけ vector<vector<Edge>> tree(N); REP(i,M) { int p,r; ll q; cin>>p>>q>>r; --p; --r; tree[r].emplace_back(p,q); } vector<ll> sum(N,0); function<void(int,ll)> dfs = [&](int x, ll n) { if (tree[x].empty()) { sum[x] += n; return; } for (auto e : tree[x]) dfs(e.to, n*e.cost); }; dfs(N-1,1); REP(i,N-1) cout<<sum[i]<<endl; } }; #if 1 int main(int argc, char *argv[]) { ios::sync_with_stdio(false); auto obj = new TakoyakiFactory(); obj->solve(); delete obj; return 0; } #endif