QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#746826#5579. Bog of Eternal Stenchwjy2020WA 40ms38440kbC++111.4kb2024-11-14 15:38:342024-11-14 15:38:35

Judging History

你现在查看的是最新测评结果

  • [2024-11-14 15:38:35]
  • 评测
  • 测评结果:WA
  • 用时:40ms
  • 内存:38440kb
  • [2024-11-14 15:38:34]
  • 提交

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]||dis[1][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: 100
Accepted
time: 40ms
memory: 36484kb

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: 36388kb

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: 0ms
memory: 38440kb

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: 0ms
memory: 36332kb

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: 3ms
memory: 36416kb

input:

2 1
1 2 0

output:

0

result:

ok single line: '0'

Test #6:

score: -100
Wrong Answer
time: 3ms
memory: 38384kb

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'