QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#746821 | #5579. Bog of Eternal Stench | wjy2020 | WA | 47ms | 38520kb | C++11 | 1.4kb | 2024-11-14 15:37:45 | 2024-11-14 15:37:45 |
Judging History
answer
#include<bits/stdc++.h>
#define int long long
#define sfor(i,j,k) for(register int i=j;i<=k;++i)
#define dfor(i,j,k) for(register int i=k;i>=j;--i)
using namespace std;
int n,m,cnt,head[1000005],dis[2005][2005],a,b,c;
priority_queue<pair<int,int>,vector<pair<int,int> >,greater<pair<int,int> > >q;
struct node{
int u,v,w,nxt;
}e[200005];
void u(int u,int v,int w){
e[++cnt].v = v;
e[cnt].u=u;
e[cnt].w = w;
e[cnt].nxt = head[u];
head[u] = cnt;
}
bool vis[2003];
void dijkstra(int s){
memset(vis,0,sizeof(vis));
dis[s][s]=0;
q.push(make_pair(0,s));
while(!q.empty()){
int x=q.top().second;
q.pop();
if(vis[x]) continue;
vis[x]=1;
for(int i = head[x];i;i = e[i].nxt)
{
int v = e[i].v;
int w = e[i].w;
if(dis[s][v] > max(dis[s][x] + w,0ll))
{
dis[s][v] = max(dis[s][x] + w,0ll);
q.push(make_pair(dis[s][v],v));
}
}
}
}
signed main(){
memset(dis,0x3f3f3f3f,sizeof(dis));
cin>>n>>m;
for(int i=1;i<=m;i++){
cin>>a>>b>>c;
u(a,b,c);
}
for(int i=1;i<=n;i++)
dijkstra(i);
int ans=dis[1][n];
for(int i=1;i<=m;i++)
if(e[i].w+dis[e[i].u][e[i].v]<0&&dis[n][e[i].u]<dis[0][0])
ans=min(ans,dis[e[i].v][n]);
cout<<max(0ll,ans)<<endl;
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 47ms
memory: 38520kb
input:
1999 1999 1 2 1000000000 2 3 1000000000 3 4 1000000000 4 5 1000000000 5 6 1000000000 6 7 1000000000 7 8 1000000000 8 9 1000000000 9 10 1000000000 10 11 1000000000 11 12 1000000000 12 13 1000000000 13 14 1000000000 14 15 1000000000 15 16 1000000000 16 17 1000000000 17 18 1000000000 18 19 1000000000 1...
output:
999000000003
result:
wrong answer 1st lines differ - expected: '3', found: '999000000003'