結果

問題 No.1364 [Renaming] Road to Cherry from Zelkova
ユーザー chocoruskchocorusk
提出日時 2021-01-22 22:51:24
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,525 bytes
コンパイル時間 1,572 ms
コンパイル使用メモリ 142,336 KB
実行使用メモリ 45,328 KB
最終ジャッジ日時 2023-08-27 21:16:39
合計ジャッジ時間 12,626 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
13,604 KB
testcase_01 AC 6 ms
13,440 KB
testcase_02 AC 6 ms
13,456 KB
testcase_03 AC 6 ms
13,292 KB
testcase_04 AC 7 ms
13,516 KB
testcase_05 AC 6 ms
13,272 KB
testcase_06 AC 6 ms
13,392 KB
testcase_07 AC 6 ms
13,312 KB
testcase_08 AC 20 ms
15,264 KB
testcase_09 AC 12 ms
13,636 KB
testcase_10 AC 20 ms
14,352 KB
testcase_11 AC 18 ms
14,736 KB
testcase_12 AC 20 ms
14,276 KB
testcase_13 AC 246 ms
32,768 KB
testcase_14 AC 309 ms
28,060 KB
testcase_15 AC 318 ms
32,080 KB
testcase_16 AC 223 ms
24,720 KB
testcase_17 AC 118 ms
28,688 KB
testcase_18 AC 428 ms
39,896 KB
testcase_19 AC 421 ms
39,912 KB
testcase_20 AC 423 ms
39,840 KB
testcase_21 AC 420 ms
40,004 KB
testcase_22 AC 421 ms
39,868 KB
testcase_23 AC 85 ms
20,004 KB
testcase_24 AC 76 ms
13,068 KB
testcase_25 AC 217 ms
21,928 KB
testcase_26 AC 336 ms
25,548 KB
testcase_27 AC 233 ms
18,684 KB
testcase_28 AC 154 ms
19,452 KB
testcase_29 AC 222 ms
18,192 KB
testcase_30 AC 159 ms
19,348 KB
testcase_31 WA -
testcase_32 AC 170 ms
16,640 KB
testcase_33 AC 309 ms
23,036 KB
testcase_34 AC 302 ms
26,708 KB
testcase_35 WA -
testcase_36 AC 318 ms
32,780 KB
testcase_37 AC 170 ms
15,864 KB
testcase_38 AC 234 ms
19,472 KB
testcase_39 AC 231 ms
19,628 KB
testcase_40 AC 232 ms
19,200 KB
testcase_41 AC 233 ms
19,184 KB
testcase_42 AC 234 ms
19,328 KB
testcase_43 AC 137 ms
45,328 KB
testcase_44 AC 103 ms
31,456 KB
testcase_45 AC 128 ms
38,952 KB
testcase_46 WA -
testcase_47 AC 6 ms
13,308 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <stack>
#include <array>
#include <list>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
const ll MOD=1e9+7;
struct SCC{
    vector<vector<int>> g, gr;
    int n, k;
    vector<int> cmp, vs;
    vector<bool> used;
    void dfs(int x){
        used[x]=1;
        for(auto y:g[x]){
            if(!used[y]) dfs(y);
        }
        vs.push_back(x);
    }
    void rdfs(int v, int k){
        used[v]=1;
        cmp[v]=k;
        for(auto y:gr[v]){
            if(!used[y]) rdfs(y, k);
        }
    }
    SCC(const vector<vector<int>> &g):g(g), n(g.size()), cmp(n), used(n){
        gr.resize(n);
        for(int x=0; x<n; x++) for(auto y:g[x]) gr[y].push_back(x);
        for(int i=0; i<n; i++){
            if(!used[i]) dfs(i);
        }
        fill(used.begin(), used.end(), 0);
        k=0;
        for(int i=vs.size()-1; i>=0; i--){
            if(!used[vs[i]]) rdfs(vs[i], k++);
        }
    }
};
int u[200010], v[200010];
ll l[200020], a[200020];
vector<P> g[200020];
int main()
{
    int n, m;
    cin>>n>>m;
    vector<vector<int>> g0(n+1);
    for(int i=0; i<m; i++){
        cin>>u[i]>>v[i]>>l[i]>>a[i];
        g[u[i]].push_back({v[i], i});
        g0[u[i]].push_back(v[i]);
    }
    SCC scc(g0);
    vector<vector<int>> w(scc.k);
    for(int i=0; i<=n; i++){
        w[scc.cmp[i]].push_back(i);
    }
    bool dame[100010]={};
    for(int i=0; i<scc.k; i++){
        if(w[i].size()>1){
            for(auto x:w[i]) dame[x]=1;
        }
    }
    if(dame[0] || dame[n]){
        cout<<"INF"<<endl;
        return 0;
    }
    ll dp[100010]={};
    dp[0]=1;
    ll dps[100010]={};
    bool ok[100010]={};
    ok[0]=1;
    for(int i=0; i<scc.k; i++){
        if(w[i].size()>1) continue;
        int x=w[i][0];
        for(auto q:g[x]){
            int i=q.second;
            int y=q.first;
            if(dame[y]) continue;
            ok[y]=1;
            (dp[y]+=dp[x]*a[i])%=MOD;
            (dps[y]+=dps[x]*a[i]+dp[x]*l[i]%MOD*a[i])%=MOD;
        }
    }
    if(!ok[n]){
        cout<<"INF"<<endl;
    }else{
        cout<<dps[n]<<endl;
    }

    return 0;
}
0