QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#746807 | #5579. Bog of Eternal Stench | wjy2020 | WA | 37ms | 36448kb | C++11 | 1.4kb | 2024-11-14 15:36:10 | 2024-11-14 15:36:11 |
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)
ans=min(ans,dis[e[i].v][n]);
cout<<max(0ll,ans)<<endl;
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 37ms
memory: 36436kb
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:
3
result:
ok single line: '3'
Test #2:
score: 0
Accepted
time: 0ms
memory: 36448kb
input:
4 4 1 2 5 1 3 -2 2 4 1 3 4 10
output:
6
result:
ok single line: '6'
Test #3:
score: 0
Accepted
time: 3ms
memory: 36372kb
input:
5 5 1 2 1000 2 3 -3 3 4 1 4 2 0 2 5 2
output:
3
result:
ok single line: '3'
Test #4:
score: 0
Accepted
time: 6ms
memory: 36376kb
input:
3 3 1 3 -10 3 2 2 2 3 -1
output:
0
result:
ok single line: '0'
Test #5:
score: 0
Accepted
time: 0ms
memory: 36372kb
input:
2 1 1 2 0
output:
0
result:
ok single line: '0'
Test #6:
score: -100
Wrong Answer
time: 0ms
memory: 36304kb
input:
6 6 1 2 1000000000 2 6 -1 3 2 0 4 3 -1 3 5 -1 5 4 -1
output:
0
result:
wrong answer 1st lines differ - expected: '999999999', found: '0'