Submission #6840623


Source Code Expand

Copy
#include <bits/stdc++.h>

#define mp make_pair
#define fst first
#define snd second
#define forn(i,n) for (int i = 0; i < int(n); i++)
#define forn1(i,n) for (int i = 1; i <= int(n); i++)
#define popcnt __builtin_popcount

using namespace std;

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,int> pli;
typedef pair<int,ll> pil;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;

template <typename T> T id(T b) {return b;};
template <class It> bool all(It f,It l){return std::all_of(f,l,id<bool>);}
template <class It> bool any(It f,It l){return std::any_of(f,l,id<bool>);}
template <typename T> void chmax(T &x, T y) {if (x < y) x = y;}
template <typename T> void chmin(T &x, T y) {if (x > y) x = y;}
void fastio() { ios_base::sync_with_stdio(false); cin.tie(nullptr); }

struct edge { int from, to, cost; };

const int MAX_N = 2500;
const int MAX_M = 5000;
int n,m,p;
edge edges[MAX_M];
ll d[MAX_N];

void bf(int r) {
  forn(i,r) {
    forn(j,m) {
      edge e = edges[j];
      if (d[e.to] > d[e.from] + e.cost) {
        d[e.to] = d[e.from] + e.cost;
      }
    }
  }
}

int main()
{
  cin >> n >> m >> p;
  forn(i,m) {
    int a,b,c; cin >> a >> b >> c;
    a--,b--;
    edges[i].from = a; edges[i].to = b; edges[i].cost = p-c;
  }

  fill_n(d,n,10000000000LL);
  d[0] = 0;

  bf(n-1);

  ll cur = d[n-1];

  bf(n);

  if (cur != d[n-1])
    cout << -1 << endl;
  else
    cout << max(0LL,-cur) << endl;

  return 0;
}

Submission Info

Submission Time
Task E - Coins Respawn
User sash0
Language C++14 (GCC 5.4.1)
Score 500
Code Size 1596 Byte
Status WA
Exec Time 135 ms
Memory 384 KB

Judge Result

Set Name Sample All after_contest
Score / Max Score 0 / 0 500 / 500 0 / 0
Status
AC × 3
AC × 56
WA × 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 1 ms 256 KB
a02 AC 1 ms 256 KB
a03 AC 1 ms 256 KB
after_contest_57 WA 22 ms 256 KB
after_contest_58 WA 21 ms 256 KB
after_contest_59 WA 21 ms 256 KB
b04 AC 1 ms 256 KB
b05 AC 1 ms 256 KB
b06 AC 1 ms 256 KB
b07 AC 1 ms 256 KB
b08 AC 1 ms 256 KB
b09 AC 17 ms 256 KB
b10 AC 22 ms 256 KB
b11 AC 17 ms 256 KB
b12 AC 17 ms 256 KB
b13 AC 17 ms 256 KB
b14 AC 17 ms 256 KB
b15 AC 5 ms 256 KB
b16 AC 5 ms 256 KB
b17 AC 5 ms 256 KB
b18 AC 21 ms 256 KB
b19 AC 22 ms 256 KB
b20 AC 17 ms 256 KB
b21 AC 17 ms 256 KB
b22 AC 18 ms 256 KB
b23 AC 21 ms 256 KB
b24 AC 17 ms 256 KB
b25 AC 2 ms 256 KB
b26 AC 33 ms 384 KB
b27 AC 33 ms 256 KB
b28 AC 32 ms 384 KB
b29 AC 34 ms 256 KB
b30 AC 34 ms 256 KB
b31 AC 33 ms 384 KB
b32 AC 33 ms 256 KB
b33 AC 33 ms 256 KB
b34 AC 34 ms 384 KB
b35 AC 35 ms 384 KB
b36 AC 36 ms 384 KB
b37 AC 36 ms 256 KB
b38 AC 32 ms 384 KB
b39 AC 32 ms 256 KB
b40 AC 33 ms 384 KB
b41 AC 32 ms 384 KB
b42 AC 33 ms 256 KB
b43 AC 126 ms 256 KB
b44 AC 120 ms 256 KB
b45 AC 135 ms 256 KB
b46 AC 110 ms 256 KB
b47 AC 95 ms 384 KB
b48 AC 17 ms 256 KB
b49 AC 21 ms 256 KB
b50 AC 21 ms 256 KB
b51 AC 17 ms 256 KB
b52 AC 21 ms 256 KB
b53 AC 17 ms 256 KB
b54 AC 32 ms 256 KB
b55 AC 39 ms 256 KB
b56 AC 45 ms 384 KB