QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#691686#7883. Takeout DeliveringcbbdhzWA 54ms38172kbC++201.9kb2024-10-31 12:37:132024-10-31 12:37:14

Judging History

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

  • [2024-10-31 12:37:14]
  • 评测
  • 测评结果:WA
  • 用时:54ms
  • 内存:38172kb
  • [2024-10-31 12:37:13]
  • 提交

answer

#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=300001;
const int M=1000001;
int head[N];
int nexxt[M<<1];
int to[M<<1];
int wei[M<<1];
int cnt=1;
void ege(int a,int b,int c)
{
    to[cnt]=b;
    wei[cnt]=c;
    nexxt[cnt]=head[a];
    head[a]=cnt++;
}
int vis1[N];int vis2[N];
signed main()
{
    ios::sync_with_stdio(false);cin.tie(0);
    int n,m;cin>>n>>m;
    vector<array<int,3>>edge;
    for(int i=1;i<=m;i++)
    {
        int a,b,c;cin>>a>>b>>c;
        edge.push_back({a,b,c});
        ege(a,b,c);ege(b,a,c);
    }
    priority_queue<array<int,2>,vector<array<int,2>>,greater<array<int,2>>>que;
    fill(vis1,vis1+n+1,INT_MAX);
    fill(vis2,vis2+n+1,INT_MAX);
    vis1[0]=0;vis2[n]=0;
    que.push({0,1});
    while(!que.empty())
    {
        auto[w,s]=que.top();que.pop();
        if(w>vis1[s])continue;
        for(int i=head[s];i!=0;i=nexxt[i])
        {
            int nt=to[i];
            if(w+wei[i]<vis1[nt])
            {
                vis1[nt]=w+wei[i];
                que.push({vis1[nt],nt});
            }
        }
    }
    que.push({0,n});
    while(!que.empty())
    {
        auto[w,s]=que.top();que.pop();
        if(w>vis2[s])continue;
        for(int i=head[s];i!=0;i=nexxt[i])
        {
            int nt=to[i];
            if(w+wei[i]<vis2[nt])
            {
                vis2[nt]=w+wei[i];
                que.push({vis2[nt],nt});
            }
        }
    }
    int ans=INT_MAX;
    for(auto[a,b,c]:edge)
    {
        if((a==1&&b==n)||(a==n&&b==1))
        {
            ans=min(ans,c);
        }
        int other1=max(vis1[a],vis2[b]);
        int other2=max(vis1[b],vis2[a]);
        if(other1<=c)
        ans=min(ans,c+other1);
        if(other2<=c)
        {
            ans=min(ans,c+other2);
        }

    }
     cout<<ans<<endl;


}

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 11848kb

input:

4 6
1 2 2
1 3 4
1 4 7
2 3 1
2 4 3
3 4 9

output:

5

result:

ok 1 number(s): "5"

Test #2:

score: -100
Wrong Answer
time: 54ms
memory: 38172kb

input:

300000 299999
80516 80517 597830404
110190 110191 82173886
218008 218009 954561262
250110 250111 942489774
66540 66541 156425292
34947 34948 239499776
273789 273790 453201232
84428 84429 439418398
98599 98600 326095035
55636 55637 355015760
158611 158612 684292473
43331 43332 43265001
171621 171622 ...

output:

2147483647

result:

wrong answer 1st numbers differ - expected: '1999991697', found: '2147483647'