結果
| 問題 |
No.30 たこやき工場
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-01-09 18:32:00 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,096 bytes |
| コンパイル時間 | 2,123 ms |
| コンパイル使用メモリ | 182,888 KB |
| 実行使用メモリ | 6,824 KB |
| 最終ジャッジ日時 | 2024-11-23 04:02:13 |
| 合計ジャッジ時間 | 2,972 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | WA * 17 |
ソースコード
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
using lint=long long;
template<class T> struct edge{
int to;
T wt;
edge(int to,const T& wt):to(to),wt(wt){}
};
template<class T> using weighted_graph=vector<vector<edge<T>>>;
template<class T>
vector<int> topological_order(const weighted_graph<T>& D){
int n=D.size();
vector<int> deg(n);
rep(u,n) for(const auto& e:D[u]) deg[e.to]++;
vector<int> res;
queue<int> Q;
rep(u,n) if(deg[u]==0) Q.emplace(u);
while(!Q.empty()){
int u=Q.front(); Q.pop();
res.emplace_back(u);
for(const auto& e:D[u]) if(--deg[e.to]==0) Q.emplace(e.to);
}
return res;
}
int main(){
int n,m; scanf("%d%d",&n,&m);
weighted_graph<lint> G(n);
rep(i,m){
int u,v,c; scanf("%d%d%d",&u,&c,&v); u--; v--;
G[u].emplace_back(v,c);
}
auto ord=topological_order(G);
reverse(ord.begin(),ord.end());
vector<lint> ans(n);
vector<bool> leaf(n,true);
ans[n-1]=1;
for(int u:ord) for(const auto& e:G[u]) {
ans[u]+=ans[e.to]*e.wt;
leaf[e.to]=false;
}
rep(u,n) printf("%lld\n",leaf[u]?ans[u]:0LL);
return 0;
}