結果

問題 No.1364 [Renaming] Road to Cherry from Zelkova
ユーザー HaaHaa
提出日時 2021-01-22 22:46:36
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,766 bytes
コンパイル時間 2,025 ms
コンパイル使用メモリ 178,116 KB
実行使用メモリ 21,540 KB
最終ジャッジ日時 2023-08-27 21:00:52
合計ジャッジ時間 10,955 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
9,180 KB
testcase_01 AC 6 ms
9,012 KB
testcase_02 AC 6 ms
9,072 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 66 ms
11,676 KB
testcase_24 AC 76 ms
11,440 KB
testcase_25 AC 168 ms
15,148 KB
testcase_26 AC 261 ms
19,060 KB
testcase_27 AC 206 ms
17,568 KB
testcase_28 AC 123 ms
13,436 KB
testcase_29 AC 203 ms
17,400 KB
testcase_30 AC 126 ms
13,704 KB
testcase_31 AC 86 ms
12,380 KB
testcase_32 AC 164 ms
16,608 KB
testcase_33 AC 255 ms
18,340 KB
testcase_34 AC 224 ms
17,060 KB
testcase_35 WA -
testcase_36 AC 218 ms
16,468 KB
testcase_37 AC 167 ms
15,412 KB
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 WA -
testcase_43 AC 108 ms
21,540 KB
testcase_44 AC 80 ms
14,376 KB
testcase_45 AC 98 ms
16,744 KB
testcase_46 AC 7 ms
10,244 KB
testcase_47 AC 6 ms
9,068 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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);
            }
        }
    }
}

void initdfs(int v){
    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]){
        cout << "INF" << endl;
        return 0;
    }
    inc[0]++;
    initdfs(0);
    lp[0]=1;
    dfs(0);
    cout << ww[n-1] << endl;
    return 0;
}
0