結果

問題 No.30 たこやき工場
ユーザー Lanatus
提出日時 2023-11-21 01:03:54
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 2,019 bytes
コンパイル時間 1,471 ms
コンパイル使用メモリ 146,420 KB
最終ジャッジ日時 2025-02-17 22:38:12
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 3 WA * 14
権限があれば一括ダウンロードができます

ソースコード

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;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0