結果
問題 | No.1364 [Renaming] Road to Cherry from Zelkova |
ユーザー | Haa |
提出日時 | 2021-01-22 22:51:26 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,872 bytes |
コンパイル時間 | 2,039 ms |
コンパイル使用メモリ | 177,856 KB |
実行使用メモリ | 21,472 KB |
最終ジャッジ日時 | 2023-08-27 21:16:58 |
合計ジャッジ時間 | 11,048 ms |
ジャッジサーバーID (参考情報) |
judge11 / judge14 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 5 ms
8,824 KB |
testcase_01 | AC | 6 ms
8,988 KB |
testcase_02 | AC | 5 ms
8,876 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 | 67 ms
11,668 KB |
testcase_24 | AC | 76 ms
11,404 KB |
testcase_25 | AC | 178 ms
15,304 KB |
testcase_26 | AC | 284 ms
19,012 KB |
testcase_27 | AC | 216 ms
17,584 KB |
testcase_28 | AC | 127 ms
13,580 KB |
testcase_29 | AC | 209 ms
17,232 KB |
testcase_30 | AC | 130 ms
13,672 KB |
testcase_31 | AC | 85 ms
12,228 KB |
testcase_32 | AC | 166 ms
16,528 KB |
testcase_33 | AC | 268 ms
18,368 KB |
testcase_34 | AC | 236 ms
16,804 KB |
testcase_35 | AC | 226 ms
16,488 KB |
testcase_36 | AC | 225 ms
16,632 KB |
testcase_37 | AC | 169 ms
15,388 KB |
testcase_38 | WA | - |
testcase_39 | WA | - |
testcase_40 | WA | - |
testcase_41 | WA | - |
testcase_42 | WA | - |
testcase_43 | AC | 108 ms
21,472 KB |
testcase_44 | AC | 82 ms
13,740 KB |
testcase_45 | AC | 99 ms
16,864 KB |
testcase_46 | AC | 8 ms
10,372 KB |
testcase_47 | AC | 5 ms
9,064 KB |
ソースコード
#include <bits/stdc++.h> using namespace std; typedef long long int ll; typedef pair<ll,ll> P; typedef vector<ll> VI; typedef vector<VI> VVI; #define REP(i,n) for(int i=0;i<(n);i++) #define ALL(v) v.begin(),v.end() constexpr ll MOD=1000000007; constexpr ll INF=1e18; struct E{ int to; ll l; ll a; int id; }; int n, m; int M=110000; vector<vector<E>> edge(M,vector<E>(0)); vector<bool> lop(M,true); VI inc(M,0); VI ways(M,0); void dag(){ VI h(n,0); REP(i,n){ for(auto nx:edge[i]){ h[nx.to]++; } } queue<int> q; REP(i,n){ if(h[i]==0){ q.push(i); } } while(!q.empty()){ int v=q.front(); lop[v]=0; q.pop(); for(auto nx:edge[v]){ if(--h[nx.to]==0){ q.push(nx.to); } } } } bool ok=1; void initdfs(int v){ if(v==n-1) ok=0; for(auto nx:edge[v]){ inc[nx.to]++; if(inc[nx.to]==1) initdfs(nx.to); } } void initdfs2(int v){ for(auto nx:edge[v]){ inc[nx.to]--; if(lop[v]) lop[nx.to]=1; if(inc[nx.to]==0) initdfs2(nx.to); } } VI ww(M,0), lp(M,0); void dfs(int v){ for(auto nx:edge[v]){ ww[nx.to]=(ww[nx.to]+ww[v]+lp[v]*nx.a%MOD*nx.l%MOD)%MOD; lp[nx.to]=(lp[nx.to]+lp[v]*nx.a)%MOD; if(--inc[nx.to]==0) dfs(nx.to); } } int main(){ cin >> n >> m; n++; int u, v, l, a; REP(i,m){ cin >> u >> v >> l >> a; edge[u].push_back(E{v,l,a,i}); } dag(); initdfs(0); initdfs2(0); if(lop[n-1]){ if(!ok) cout << "INF" << endl; if(ok) cout << 0 << endl; return 0; } inc[0]++; initdfs(0); lp[0]=1; dfs(0); cout << ww[n-1] << endl; return 0; }