結果

問題 No.30 たこやき工場
ユーザー LanatusLanatus
提出日時 2023-11-21 01:03:54
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,019 bytes
コンパイル時間 1,812 ms
コンパイル使用メモリ 152,524 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2023-11-21 01:03:57
合計ジャッジ時間 2,737 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <exception>
#include <functional>
#include <iomanip>
#include <ios>
#include <iostream>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

const int MOD = 1e9 + 7;

using ld = long double;
using ll = long long;
using ull = unsigned long long;

template<class T> using pq = priority_queue<T>;
template<class T> using pqg = priority_queue<T, vector<T>, greater<T>>;

template<class T, class U> inline bool chmin(T& a, const U& b) { if (a > b) { a = b; return 1; } return 0; }
template<class T, class U> inline bool chmax(T& a, const U& b) { if (a < b) { a = b; return 1; } return 0; }

template<class T> auto min(const T& a) { *min_elemenet(all(a)); }
template<class T> auto max(const T& a) { *max_elemenet(all(a)); }

// const ll MOD = 1e9 + 7;
const ll INF = 1 << 30;
const ll INFLL = 1LL << 60;
const ld EPS = 1e-9;

const ll dx[] = {0, 1, 0, -1, 1, -1, 1, -1};
const ll dy[] = {1, 0, -1, 0, 1, -1, -1, 1};

#define all(v) begin(v), end(v)


int n, m;
vector<vector<pair<int,ll>>> G;
vector<int> used;
vector<map<int,ll>> memo;


map<int,ll> dp(int v) {
  if (used[v]) return memo[v];
  used[v] = true;

  if (G[v].empty()) return { { v, 1 } };

  map<int,ll> &ret = memo[v];
  for (auto& [to, cost] : G[v]) {
    for (auto& [material, num] : dp(to)) {
      ret[material] += num * cost;
    }
  }

  return ret;
}


int main(void) {
  cin >> n >> m;

  G.resize(n);
  memo.resize(n);
  used.assign(n, 0);

  for (int i = 0; i < m; ++i) {
    int a, b, c;
    cin >> a >> b >> c;

    G[c - 1].push_back({a - 1, b});
  }

  auto ret = dp(n - 1);
  for (int i = 0; i < n - 1; ++i) {
    cout << ret[i] << endl;
  }
  return 0;
}
0