QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#775724#5579. Bog of Eternal Stenchydzr00000WA 2ms5912kbC++171.5kb2024-11-23 16:33:192024-11-23 16:33:21

Judging History

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

  • [2024-11-23 16:33:21]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:5912kb
  • [2024-11-23 16:33:19]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
vector<pair<int,int>>e[2001];
long long dis[2001];
bool inQ[2001];
int tim[2001];
int Q[4000001];
int main(){
    int n,m;
    scanf("%d %d",&n,&m);
    for(int i=1;i<=m;i++)
    {
        int u,v,w;
        scanf("%d %d %d",&u,&v,&w);
        e[v].push_back({u,-w});
    }
    auto check=[&](const long long &val)->bool
    {
        memset(dis,-0x3f,sizeof(dis));
        memset(tim,0,sizeof(tim));
        memset(inQ,false,sizeof(inQ));
        int head=1,tail=0;
        Q[++tail]=n;inQ[n]=true;tim[n]=1;
        dis[n]=val;
        while(head<=tail)
        {
            int u=Q[head++];
            inQ[u]=false;
            for(auto [v,w]: e[u])
            {
                if(dis[u]+w<0)
                    continue;
                if(dis[v]<dis[u]+w)
                {
                    dis[v]=dis[u]+w;
                    tim[v]=tim[u]+1;
                    if(tim[v]>=n)
                        return true;
                    if(!inQ[v])
                    {
                        inQ[v]=true;
                        Q[++tail]=v;
                    }
                }
            }
        }
        return dis[1]>=0;
    };
    long long l=0,r=1e18,ans=-1;
    while(l<=r)
    {
        long long mid=(l+r)>>1;
        if(check(mid))
        {
            ans=mid;
            r=mid-1;
        }
        else
            l=mid+1;
    }
    printf("%lld\n",ans);
    
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 5912kb

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: 1ms
memory: 3940kb

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: 1ms
memory: 3944kb

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: 1ms
memory: 3928kb

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: 1ms
memory: 3960kb

input:

2 1
1 2 0

output:

0

result:

ok single line: '0'

Test #6:

score: -100
Wrong Answer
time: 1ms
memory: 3896kb

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'