結果

問題 No.1364 [Renaming] Road to Cherry from Zelkova
ユーザー 夕叢霧香(ゆうむらきりか)夕叢霧香(ゆうむらきりか)
提出日時 2021-01-22 00:37:54
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 969 bytes
コンパイル時間 1,955 ms
コンパイル使用メモリ 84,372 KB
実行使用メモリ 18,632 KB
最終ジャッジ日時 2023-08-28 10:59:48
合計ジャッジ時間 9,976 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,728 KB
testcase_01 AC 3 ms
5,820 KB
testcase_02 AC 3 ms
5,816 KB
testcase_03 AC 3 ms
5,704 KB
testcase_04 AC 3 ms
5,944 KB
testcase_05 AC 2 ms
5,696 KB
testcase_06 AC 2 ms
5,708 KB
testcase_07 AC 3 ms
5,716 KB
testcase_08 AC 12 ms
6,052 KB
testcase_09 AC 7 ms
5,856 KB
testcase_10 AC 13 ms
6,048 KB
testcase_11 AC 11 ms
6,124 KB
testcase_12 AC 14 ms
6,288 KB
testcase_13 AC 158 ms
9,156 KB
testcase_14 AC 235 ms
10,536 KB
testcase_15 AC 219 ms
9,996 KB
testcase_16 AC 162 ms
9,328 KB
testcase_17 AC 73 ms
7,712 KB
testcase_18 AC 281 ms
10,640 KB
testcase_19 AC 284 ms
10,604 KB
testcase_20 AC 283 ms
10,936 KB
testcase_21 AC 282 ms
10,792 KB
testcase_22 AC 282 ms
11,072 KB
testcase_23 AC 63 ms
7,384 KB
testcase_24 AC 72 ms
6,500 KB
testcase_25 AC 171 ms
10,236 KB
testcase_26 AC 269 ms
12,148 KB
testcase_27 AC 206 ms
10,004 KB
testcase_28 AC 121 ms
8,860 KB
testcase_29 AC 199 ms
9,340 KB
testcase_30 AC 125 ms
8,988 KB
testcase_31 AC 83 ms
8,096 KB
testcase_32 AC 158 ms
8,916 KB
testcase_33 AC 255 ms
11,728 KB
testcase_34 AC 231 ms
12,128 KB
testcase_35 AC 214 ms
8,784 KB
testcase_36 AC 216 ms
8,792 KB
testcase_37 AC 162 ms
8,140 KB
testcase_38 AC 220 ms
8,588 KB
testcase_39 AC 221 ms
8,596 KB
testcase_40 AC 221 ms
8,720 KB
testcase_41 AC 221 ms
8,524 KB
testcase_42 AC 221 ms
8,680 KB
testcase_43 AC 100 ms
18,632 KB
testcase_44 AC 74 ms
8,120 KB
testcase_45 AC 98 ms
18,028 KB
testcase_46 AC 2 ms
5,708 KB
testcase_47 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<algorithm>
#include<cassert>
#include<tuple>
#include<iostream>
#include<vector>
using namespace std;
typedef long long lint;
typedef vector<int>vi;
typedef pair<int,int>pii;
typedef tuple<int,int,int>tri;
#define rep(i,n)for(int i=0;i<(int)(n);++i)

const lint mod=1e9+7;
const int N=100001;
int n,m;
vector<tri>g[N];
//dp1:通り数,dp2:長さの合計
lint dp1[N],dp2[N];
bool inf[N];
int st[N];

void dfs(int v){
  if(st[v]==1){
    inf[v]=1;
    st[v]=2;
    return;
  }
  if(st[v]==2){
    return;
  }
  st[v]=1;
  dp1[v]=v==n?1:0;
  for(tri wlk:g[v]){
    int w,l,k;
    tie(w,l,k)=wlk;
    
    dfs(w);
    if(inf[w]){
      inf[v]=1;
    }else{
      dp1[v]=(dp1[v]+dp1[w]*k)%mod;
      dp2[v]=(dp2[v]+dp2[w]*k+dp1[w]*k%mod*l)%mod;
    }
  }
  st[v]=2;
}

int main(){
  cin>>n>>m;
  rep(_,m){
    int a,b,l,k;cin>>a>>b>>l>>k;
    g[a].push_back(tri(b,l,k));
  }
  dfs(0);
  if(inf[0]){
    cout<<"INF"<<endl;
    return 0;
  }
  cout<<dp2[0]<<endl;
}
0