Submission #6823363


Source Code Expand

Copy
#include<bits/stdc++.h>
using namespace std;
const long long N = 2500 + 5;
long long n, m, p;
vector < pair < long long , long long > > g[N], g2[N];
bool vis[N], vis2[N], instk[N];
vector < pair < long long , long long > > temp;
bool yes;
vector < pair < long long, long long >  > v;
bool check(long long node){
  if (vis2[node])
    return 0;
  vis2[node] = 1;
  if (node == n)
    return 1;
  bool ret = 0;
  for(auto ch : g[node])
    ret |= check(ch.first);
  return ret;
}
bool reachable[N];
void dfs(long long node){
  reachable[node] = 1;
  if (vis[node]){
    if (instk[node]){
    long long cost = 0;
    for(long long i = v.size() -1  ; i >= 0 ; i--){
      cost += v[i].second - p;
      if (v[i].first == node)
        break;
    }
    if (cost > 0){
      memset(vis2,0,sizeof vis2);
      if (check(node))
        yes = 1;
    }
  }
    return;
  }
  instk[node] = 1;
  vis[node] = 1;
  for(auto ch : g[node]){
    v.push_back({node, ch.second});
    dfs(ch.first);
    v.pop_back();
  }
  instk[node] = 0;
}
long long co[N];
long long topo(long long node){
  // cout << node << endl;
  if (node == 1)
    return 0;
  if (vis[node])
    return co[node];
  vis[node] = 1;
  long long ret = -1e16;
  for(auto ch : g2[node]){
    if (ch.first == node)
      continue;
    ret = max(ret, ch.second - p + topo(ch.first));
  }
  return co[node] = ret;
}
int main(){
  cin >> n >> m >> p;
  for(long long i = 1 ; i <= m ; i++){
    long long x, y, c;
    cin >> x >> y >> c;
    g[x].push_back({y, c});
    g2[y].push_back({x, c});
  }
  dfs(1);
  if (yes)
    return cout << -1,0;
  memset(vis,0,sizeof vis);
  long long ret = topo(n);
  cout << max(0LL,ret);
  return 0;
}

Submission Info

Submission Time
Task E - Coins Respawn
User Bohoty
Language C++14 (GCC 5.4.1)
Score 0
Code Size 1762 Byte
Status WA
Exec Time 36 ms
Memory 896 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 500
Status
AC × 3
AC × 41
WA × 15
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
Case Name Status Exec Time Memory
a01 AC 1 ms 384 KB
a02 AC 1 ms 384 KB
a03 AC 1 ms 384 KB
b04 AC 1 ms 384 KB
b05 AC 1 ms 384 KB
b06 AC 1 ms 384 KB
b07 AC 1 ms 384 KB
b08 AC 1 ms 384 KB
b09 AC 3 ms 768 KB
b10 AC 4 ms 768 KB
b11 AC 4 ms 896 KB
b12 AC 3 ms 896 KB
b13 AC 4 ms 896 KB
b14 AC 4 ms 768 KB
b15 AC 4 ms 640 KB
b16 WA 4 ms 640 KB
b17 AC 4 ms 640 KB
b18 AC 4 ms 768 KB
b19 AC 4 ms 768 KB
b20 AC 4 ms 768 KB
b21 AC 4 ms 896 KB
b22 AC 3 ms 512 KB
b23 AC 4 ms 896 KB
b24 WA 3 ms 640 KB
b25 AC 1 ms 384 KB
b26 WA 6 ms 768 KB
b27 WA 6 ms 768 KB
b28 WA 6 ms 768 KB
b29 WA 6 ms 768 KB
b30 WA 6 ms 768 KB
b31 WA 6 ms 768 KB
b32 WA 6 ms 768 KB
b33 WA 6 ms 640 KB
b34 WA 6 ms 640 KB
b35 WA 6 ms 640 KB
b36 AC 6 ms 640 KB
b37 AC 6 ms 640 KB
b38 WA 6 ms 640 KB
b39 WA 6 ms 640 KB
b40 WA 6 ms 640 KB
b41 AC 6 ms 640 KB
b42 AC 6 ms 640 KB
b43 AC 36 ms 768 KB
b44 AC 11 ms 768 KB
b45 AC 8 ms 768 KB
b46 AC 6 ms 768 KB
b47 AC 6 ms 640 KB
b48 AC 3 ms 512 KB
b49 AC 4 ms 768 KB
b50 AC 3 ms 768 KB
b51 AC 3 ms 768 KB
b52 AC 3 ms 768 KB
b53 AC 4 ms 896 KB
b54 AC 5 ms 640 KB
b55 AC 6 ms 768 KB
b56 AC 6 ms 768 KB