結果
問題 | No.1364 [Renaming] Road to Cherry from Zelkova |
ユーザー | siman |
提出日時 | 2022-04-10 03:13:49 |
言語 | C++17(clang) (17.0.6 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,790 bytes |
コンパイル時間 | 3,429 ms |
コンパイル使用メモリ | 89,124 KB |
実行使用メモリ | 27,796 KB |
最終ジャッジ日時 | 2023-08-20 06:59:07 |
合計ジャッジ時間 | 18,613 ms |
ジャッジサーバーID (参考情報) |
judge11 / judge14 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
4,880 KB |
testcase_01 | AC | 1 ms
4,884 KB |
testcase_02 | AC | 2 ms
4,884 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 | - |
testcase_17 | WA | - |
testcase_18 | WA | - |
testcase_19 | WA | - |
testcase_20 | WA | - |
testcase_21 | WA | - |
testcase_22 | WA | - |
testcase_23 | AC | 80 ms
11,344 KB |
testcase_24 | AC | 79 ms
4,980 KB |
testcase_25 | AC | 213 ms
13,080 KB |
testcase_26 | AC | 341 ms
15,708 KB |
testcase_27 | AC | 253 ms
9,764 KB |
testcase_28 | AC | 154 ms
10,760 KB |
testcase_29 | AC | 236 ms
9,496 KB |
testcase_30 | AC | 159 ms
10,780 KB |
testcase_31 | AC | 105 ms
11,748 KB |
testcase_32 | AC | 179 ms
8,600 KB |
testcase_33 | AC | 331 ms
13,396 KB |
testcase_34 | AC | 305 ms
17,028 KB |
testcase_35 | WA | - |
testcase_36 | WA | - |
testcase_37 | AC | 180 ms
7,588 KB |
testcase_38 | WA | - |
testcase_39 | WA | - |
testcase_40 | WA | - |
testcase_41 | WA | - |
testcase_42 | WA | - |
testcase_43 | AC | 126 ms
25,992 KB |
testcase_44 | AC | 91 ms
16,412 KB |
testcase_45 | AC | 124 ms
25,288 KB |
testcase_46 | AC | 13 ms
13,932 KB |
testcase_47 | WA | - |
ソースコード
#include <iostream> #include <stack> #include <string.h> #include <vector> using namespace std; typedef long long ll; const ll MOD = 1000000007; typedef vector <vector<int>> Graph; typedef vector <vector<ll>> Cost; typedef vector <vector<ll>> Nums; vector<int> tsort(Graph G, int start, int end) { vector<int> ret; int degree[end]; memset(degree, 0, sizeof(degree)); for (int from = start; from < end; from++) { for (int i = 0; i < G[from].size(); i++) { int to = G[from][i]; degree[to]++; } } stack<int> root; for (int i = start; i < end; i++) { if (degree[i] == 0) { root.push(i); } } while (!root.empty()) { int from = root.top(); root.pop(); ret.push_back(from); for (int i = 0; i < G[from].size(); i++) { int to = G[from][i]; degree[to]--; if (degree[to] == 0) { root.push(to); } } } return ret; } int main() { int N, M; cin >> N >> M; Graph G(N + 1); Cost C(N + 1); Nums D(N + 1); int s, t; ll l, a; for (int i = 0; i < M; ++i) { cin >> s >> t >> l >> a; G[s].push_back(t); C[s].push_back(l); D[s].push_back(a); } vector<int> res = tsort(G, 0, N + 1); if (res.size() != N + 1) { // tsort failed. cout << "INF" << endl; } else { ll dp_C[N + 1]; ll dp_D[N + 1]; memset(dp_C, 0, sizeof(dp_C)); memset(dp_D, 0, sizeof(dp_D)); dp_D[0] = 1; for (int v : res) { int L = G[v].size(); for (int i = 0; i < L; ++i) { int u = G[v][i]; ll c = C[v][i]; ll d = D[v][i]; dp_C[u] += dp_C[v] + dp_D[v] * d * c; dp_D[u] += dp_D[v] * d; dp_C[u] %= MOD; dp_D[u] %= MOD; } } cout << dp_C[N] << endl; } return 0; }