結果
| 問題 | No.30 たこやき工場 | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2025-05-16 21:12:26 | 
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                RE
                                 
                             | 
| 実行時間 | - | 
| コード長 | 1,143 bytes | 
| コンパイル時間 | 2,860 ms | 
| コンパイル使用メモリ | 206,928 KB | 
| 実行使用メモリ | 7,844 KB | 
| 最終ジャッジ日時 | 2025-05-16 21:12:31 | 
| 合計ジャッジ時間 | 4,102 ms | 
| ジャッジサーバーID (参考情報) | judge2 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 11 RE * 6 | 
ソースコード
#include <bits/stdc++.h>
using namespace std;
vector<int> topolo(vector<vector<pair<int,long long>>> &Graph){
    int siz = Graph.size();
    vector<int> ret,inV(siz);
    for(auto u : Graph) for(auto [to,w] : u) inV.at(to)++;
    queue<int> Q;
    for(int i=siz-1; i<siz; i++) if(inV.at(i) == 0) Q.push(i);
    while(Q.size()){
        int pos = Q.front(); Q.pop();
        ret.push_back(pos);
        for(auto [to,w] : Graph.at(pos)){
            inV.at(to)--;
            if(inV.at(to) == 0) Q.push(to);
        }
    }
    return ret;
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
 
    int N,M; cin >> N >> M;
    vector<vector<pair<int,long long>>> Graph(N),rev(N);
    for(int i=0; i<M; i++){
        int a,b,c; cin >> a >> b >> c; a--; c--;
        assert(a != N-1); 
        Graph.at(c).push_back({a,b});
    }
    auto topo = topolo(Graph);
    vector<long long> need(N); need.at(N-1) = 1;
    for(auto pos : topo) for(auto [to,w] : Graph.at(pos)) need.at(to) += need.at(pos)*w;
    for(int i=0; i<N-1; i++){
        if(Graph.at(i).size()) cout << "0\n";
        else cout << need.at(i) << "\n";
    }
}
            
            
            
        