Submission #6820913


Source Code Expand

Copy
#include <queue>
#include <cstdio>
#include <string>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;

const int N=5e3+2;

template <typename _Tp> inline void IN(_Tp&x) {
    char ch;bool flag=0;x=0;
    while(ch=getchar(),!isdigit(ch)) if(ch=='-') flag=1;
    while(isdigit(ch)) x=x*10+ch-'0',ch=getchar();
    if(flag) x=-x;
}

int head[N],dis[N],vis[N],QAQ[N],cnt,n,m,p;
struct Edge {int nxt,w,to;} G[N<<1]; 
inline void add(int u,int v,int w) {
	G[++cnt].nxt=head[u],G[cnt].to=v,G[cnt].w=w,head[u]=cnt;
}
inline void Spfa() {
	memset(dis,127,sizeof(dis));
    int inf=-(1e9+7);
	deque<int> q;q.push_back(1),dis[1]=0,vis[1]=true;
	while(!q.empty()) {
		int u=q.front();q.pop_front();++QAQ[u],vis[u]=false;
        if(QAQ[u]>=n) dis[u]=inf;
		for(int i=head[u];i;i=G[i].nxt) {
			int v=G[i].to;
			if(dis[u]+G[i].w<dis[v]&&QAQ[v]<n) {
				dis[v]=dis[u]+G[i].w;     
			    if(vis[v]==false)
				    v<q.front()?q.push_front(v):q.push_back(v),vis[v]=true; 
		    }
		}
	}
}

int main() {
    IN(n),IN(m),IN(p);
    for(int i=1,a,b,c;i<=m;++i)
        IN(a),IN(b),IN(c),add(a,b,-(c-p));
    Spfa();
    if(dis[n]<-5e8) puts("-1");
    else printf("%d\n",(dis[n]<0)?-dis[n]:0);
    return 0;
}

Submission Info

Submission Time
Task E - Coins Respawn
User CYJian
Language C++14 (GCC 5.4.1)
Score 500
Code Size 1295 Byte
Status AC
Exec Time 433 ms
Memory 384 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 500 / 500
Status
AC × 3
AC × 56
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 256 KB
a02 AC 1 ms 256 KB
a03 AC 1 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 2 ms 384 KB
b10 AC 2 ms 384 KB
b11 AC 433 ms 384 KB
b12 AC 432 ms 384 KB
b13 AC 44 ms 384 KB
b14 AC 2 ms 384 KB
b15 AC 2 ms 384 KB
b16 AC 2 ms 384 KB
b17 AC 2 ms 384 KB
b18 AC 2 ms 384 KB
b19 AC 2 ms 384 KB
b20 AC 433 ms 384 KB
b21 AC 63 ms 384 KB
b22 AC 1 ms 256 KB
b23 AC 2 ms 384 KB
b24 AC 1 ms 384 KB
b25 AC 1 ms 256 KB
b26 AC 2 ms 384 KB
b27 AC 2 ms 384 KB
b28 AC 2 ms 384 KB
b29 AC 143 ms 384 KB
b30 AC 140 ms 384 KB
b31 AC 135 ms 384 KB
b32 AC 3 ms 384 KB
b33 AC 3 ms 384 KB
b34 AC 4 ms 384 KB
b35 AC 4 ms 384 KB
b36 AC 5 ms 384 KB
b37 AC 5 ms 384 KB
b38 AC 2 ms 384 KB
b39 AC 2 ms 384 KB
b40 AC 2 ms 384 KB
b41 AC 2 ms 384 KB
b42 AC 2 ms 384 KB
b43 AC 22 ms 384 KB
b44 AC 103 ms 384 KB
b45 AC 144 ms 384 KB
b46 AC 143 ms 384 KB
b47 AC 2 ms 384 KB
b48 AC 1 ms 384 KB
b49 AC 2 ms 384 KB
b50 AC 1 ms 384 KB
b51 AC 2 ms 384 KB
b52 AC 1 ms 384 KB
b53 AC 63 ms 384 KB
b54 AC 2 ms 384 KB
b55 AC 2 ms 384 KB
b56 AC 2 ms 384 KB