Submission #6904276


Source Code Expand

Copy
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define ll long long
#define ld long double
#define all(a) a.begin(),a.end()
#define endl '\n'
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ull unsigned long long
#define int long long
#define iter set<int>::iterator
using namespace std;
using namespace __gnu_pbds;

template<class T>
using ordered_set=tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;

template<class T>
using ordered_multiset=tree<T,null_type,less_equal<T>,rb_tree_tag,tree_order_statistics_node_update>;

mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
mt19937_64 rnd1(chrono::steady_clock::now().time_since_epoch().count());

//find_by_order
//order_of_key

const int N=2e5+7;
const int inf=1e18+5;
const int mod=2520;

int n,m,p;
vector< pair< pair<int,int>,int > >q;
vector< pair< pair<int,int>,int > >qq;
int d[N];
int d1[N];
int d2[N];

main ()
{
    ios;
    cin>>n>>m>>p;
    for (int i=1;i<=m;++i){
        int x,y,z;
        cin>>x>>y>>z;
        z-=p;
        z=-z;
        q.pb({{x,y},z});
        qq.pb({{y,x},z});
    }
    for (int i=1;i<=n-1;++i){
        d1[i]=inf;
    }
    for (int i=1;i<=n;++i){
        for (int j=0;j<qq.size();++j){
            int x=qq[j].ff.ff;
            if (d1[x]==inf)continue;
            int y=qq[j].ff.ss;
            int cost=qq[j].ss;
            if (d1[x]+cost<d1[y]){
                d1[y]=d1[x]+cost;
            }
        }
    }
    for (int i=2;i<=n;++i){
        d[i]=inf;
    }
    for (int i=1;i<=n;++i){
        for (int j=0;j<q.size();++j){
            int x=q[j].ff.ff;
            if (d[x]==inf)continue;
            int y=q[j].ff.ss;
            int cost=q[j].ss;
            if (d[x]+cost<d[y]){
                d[y]=d[x]+cost;
            }
        }
    }
    for (int i=1;i<=n;++i){
        d2[i]=d[i];
    }
    for (int i=1;i<=2*n;++i){
        for (int j=0;j<q.size();++j){
            int x=q[j].ff.ff;
            if (d[x]==inf)continue;
            int y=q[j].ff.ss;
            int cost=q[j].ss;
            if (d[x]+cost<d[y]){
                d[y]=d[x]+cost;
            }
        }
    }
    bool t=false;
    for (int i=1;i<=n;++i){
        if (d[i]<d2[i] && d1[i]!=inf){
            t=true;
            break;
        }
    }
    if (t || d[n]==inf){
        cout<<-1<<endl;
    }
    else {
        if (d[n]<0){
            cout<<-d[n]<<endl;
        }
        else {
            cout<<0<<endl;
        }
    }
}

Submission Info

Submission Time
Task E - Coins Respawn
User DeD_TihoN
Language C++14 (GCC 5.4.1)
Score 500
Code Size 2731 Byte
Status AC
Exec Time 293 ms
Memory 2816 KB

Judge Result

Set Name Sample All after_contest
Score / Max Score 0 / 0 500 / 500 0 / 0
Status
AC × 3
AC × 56
AC × 3
Set Name Test Cases
Sample a01, a02, a03
All a01, a02, a03, b04, b05, b06, b07, b08, b09, b10, b11, b12, b13, b14, b15, b16, b17, b18, b19, b20, b21, b22, b23, b24, b25, b26, b27, b28, b29, b30, b31, b32, b33, b34, b35, b36, b37, b38, b39, b40, b41, b42, b43, b44, b45, b46, b47, b48, b49, b50, b51, b52, b53, b54, b55, b56
after_contest after_contest_57, after_contest_58, after_contest_59
Case Name Status Exec Time Memory
a01 AC 2 ms 2304 KB
a02 AC 2 ms 2304 KB
a03 AC 2 ms 2304 KB
after_contest_57 AC 47 ms 2560 KB
after_contest_58 AC 47 ms 2560 KB
after_contest_59 AC 47 ms 2560 KB
b04 AC 2 ms 2304 KB
b05 AC 2 ms 2304 KB
b06 AC 2 ms 2304 KB
b07 AC 2 ms 2304 KB
b08 AC 2 ms 2304 KB
b09 AC 44 ms 2560 KB
b10 AC 48 ms 2560 KB
b11 AC 48 ms 2560 KB
b12 AC 39 ms 2560 KB
b13 AC 39 ms 2560 KB
b14 AC 47 ms 2560 KB
b15 AC 3 ms 2816 KB
b16 AC 3 ms 2816 KB
b17 AC 3 ms 2816 KB
b18 AC 48 ms 2560 KB
b19 AC 48 ms 2560 KB
b20 AC 48 ms 2560 KB
b21 AC 48 ms 2560 KB
b22 AC 22 ms 2560 KB
b23 AC 37 ms 2560 KB
b24 AC 33 ms 2560 KB
b25 AC 2 ms 2304 KB
b26 AC 63 ms 2816 KB
b27 AC 63 ms 2816 KB
b28 AC 63 ms 2816 KB
b29 AC 66 ms 2816 KB
b30 AC 66 ms 2816 KB
b31 AC 64 ms 2816 KB
b32 AC 89 ms 2816 KB
b33 AC 99 ms 2816 KB
b34 AC 102 ms 2816 KB
b35 AC 105 ms 2816 KB
b36 AC 109 ms 2816 KB
b37 AC 111 ms 2816 KB
b38 AC 112 ms 2816 KB
b39 AC 117 ms 2816 KB
b40 AC 113 ms 2816 KB
b41 AC 106 ms 2816 KB
b42 AC 64 ms 2816 KB
b43 AC 268 ms 2816 KB
b44 AC 252 ms 2816 KB
b45 AC 293 ms 2816 KB
b46 AC 271 ms 2816 KB
b47 AC 96 ms 2816 KB
b48 AC 30 ms 2560 KB
b49 AC 48 ms 2560 KB
b50 AC 45 ms 2560 KB
b51 AC 44 ms 2560 KB
b52 AC 45 ms 2560 KB
b53 AC 48 ms 2560 KB
b54 AC 61 ms 2816 KB
b55 AC 76 ms 2816 KB
b56 AC 91 ms 2816 KB