Submission #6821415


Source Code Expand

Copy
#include<bits/stdc++.h>
using namespace std;
const int N = 2500 + 5;
int n, m, p;
vector < pair < int , int > > g[N], g2[N];
bool vis[N], vis2[N], instk[N];
vector < pair < int , int > > temp;
bool yes;
vector < pair < int, int >  > v;
bool check(int 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(int node){
  reachable[node] = 1;
  if (vis[node]){
    if (instk[node]){
    long long cost = 0;
    for(int 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;
}
int co[N];
long long topo(int node){
  if (!reachable[node])
    return -1e16;
  if (vis[node])
    return co[node];
  vis[node] = 1;
  long long ret = 0;
  for(auto ch : g2[node]){
    ret = max(ret, ch.second - p + topo(ch.first));
  }
  return co[node] = ret;
}
int main(){
  cin >> n >> m >> p;
  for(int i = 1 ; i <= m ; i++){
    int 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 << ret;
  return 0;
}

Submission Info

Submission Time
Task E - Coins Respawn
User Bohoty
Language C++14 (GCC 5.4.1)
Score 0
Code Size 1598 Byte
Status WA
Exec Time 36 ms
Memory 768 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 4 ms 768 KB
b10 AC 4 ms 768 KB
b11 AC 4 ms 768 KB
b12 AC 3 ms 768 KB
b13 AC 4 ms 768 KB
b14 AC 4 ms 768 KB
b15 AC 5 ms 512 KB
b16 WA 5 ms 512 KB
b17 AC 5 ms 512 KB
b18 AC 4 ms 768 KB
b19 AC 4 ms 768 KB
b20 AC 4 ms 768 KB
b21 AC 4 ms 768 KB
b22 AC 4 ms 512 KB
b23 AC 4 ms 768 KB
b24 AC 4 ms 512 KB
b25 AC 1 ms 384 KB
b26 WA 7 ms 640 KB
b27 WA 7 ms 640 KB
b28 WA 7 ms 640 KB
b29 WA 7 ms 640 KB
b30 WA 7 ms 640 KB
b31 WA 7 ms 640 KB
b32 WA 7 ms 640 KB
b33 WA 7 ms 640 KB
b34 WA 6 ms 512 KB
b35 WA 7 ms 512 KB
b36 AC 7 ms 512 KB
b37 AC 7 ms 512 KB
b38 WA 7 ms 640 KB
b39 WA 7 ms 640 KB
b40 WA 6 ms 640 KB
b41 AC 6 ms 512 KB
b42 WA 6 ms 512 KB
b43 AC 36 ms 640 KB
b44 AC 11 ms 640 KB
b45 AC 9 ms 640 KB
b46 AC 7 ms 640 KB
b47 AC 6 ms 512 KB
b48 AC 3 ms 512 KB
b49 AC 4 ms 768 KB
b50 AC 4 ms 768 KB
b51 AC 4 ms 768 KB
b52 AC 4 ms 768 KB
b53 AC 4 ms 768 KB
b54 AC 6 ms 512 KB
b55 AC 7 ms 640 KB
b56 AC 7 ms 640 KB