結果
| 問題 | No.30 たこやき工場 |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-01-19 05:22:41 |
| 言語 | C++23 (gcc 15.2.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 5,000 ms |
| コード長 | 1,409 bytes |
| 記録 | |
| コンパイル時間 | 4,594 ms |
| コンパイル使用メモリ | 359,112 KB |
| 実行使用メモリ | 7,848 KB |
| 最終ジャッジ日時 | 2026-01-19 05:22:47 |
| 合計ジャッジ時間 | 5,785 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 17 |
ソースコード
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
using ll=long long;
vector<int> toposort(const int n,const vector<pair<int,int>>& edges){
queue<int> que;
vector<int> indegree(n);
vector<vector<int>> adj(n);
for(auto& [u,v]: edges){
++indegree[v];
adj[u].emplace_back(v);
}
for(int i=0;i<n;++i)if(!indegree[i]){
que.emplace(i);
}
vector<int> ret;
while(!que.empty()){
const int u=que.front(); que.pop();
ret.emplace_back(u);
for(int&v:adj[u])if(!--indegree[v])que.emplace(v);
}
return ret;
}
void solve(){
int N,M;cin>>N>>M;
vector<pair<int,int>> edges;
vector<vector<pair<int,int>>> material(N);
for(int i=0;i<M;++i){
int u,c,v;cin>>u>>c>>v;
--u,--v;
edges.emplace_back(u,v);
material[v].emplace_back(u,c);
}
auto order=toposort(N,edges);
ranges::reverse(order);
vector<ll> ans(N);
ans.at(N-1)=1;
for(auto&u:order){
for(auto&[v,cost]:material[u]){
ans[v]+=ans[u]*cost;
}
if(!material[u].empty())ans[u]=0;
}
ans.erase(prev(ans.end()));
for(auto&c:ans)cout<<c<<'\n';
}
int main(){
ios::sync_with_stdio(0);
cin.tie(nullptr);
int T=1; // cin>>T;
while(T--)solve();
return 0;
}