結果

問題 No.30 たこやき工場
ユーザー motimoti
提出日時 2020-03-08 14:58:46
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 1,208 bytes
コンパイル時間 4,557 ms
コンパイル使用メモリ 132,360 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-23 05:22:07
合計ジャッジ時間 5,627 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)

#define INF (1<<29)

struct Edge
{
  int dst;
  int cost;
  Edge(int d, int c) : dst(d), cost(c) {}
};

vector<Edge> G[110];

typedef pair<int, int> Pii;

int N, M;
/*
vector<int> get(int st)
{
  vector<int> ans(N-1);
  
  queue<Pii> Q;
  Q.push(Pii(st, 1));
  while(!Q.empty()) {
    int pos = Q.front().first;
    int cost = Q.front().second; Q.pop();
    ans[pos] += cost;
    rep(i, G[pos].size()) {
      Q.push(Pii(G[pos][i].dst, G[pos][i].cost*cost));
    }
  }
  
  return ans;
}
*/

int ans[110];

int get(int pos)
{
  int& res = ans[pos];
  if(res != -1) return res;
  //if(G[pos].empty()) return res = 1;
  if(pos == N-1) return res = 1;
  
  res = 0;
  rep(i, G[pos].size()) {
    res += get(G[pos][i].dst) * G[pos][i].cost;
  }
  
  return res;
}

int main() {
  
  cin >> N >> M;
  
  bool isntLast[110] = {};
  rep(i, M) {
    int p, q, r;
    cin >> p >> q >> r; p --, r --;
    G[p].push_back(Edge(r, q));
    isntLast[r] = 1;
  }
  
  memset(ans, -1, sizeof ans);
  rep(i, N-1) {
    if(isntLast[i]) cout << 0 << endl;
    else cout << get(i) << endl;
  }
  
  return 0;
}
0