QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#691618 | #7883. Takeout Delivering | cbbdhz | WA | 226ms | 24172kb | C++20 | 1.7kb | 2024-10-31 12:16:40 | 2024-10-31 12:16:41 |
Judging History
answer
#include<bits/stdc++.h>
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()
{
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 other=min(max(vis1[a],vis2[b]),max(vis1[b],vis2[a]));
if(other>c)continue;
ans=min(ans,c+other);
}
cout<<ans<<endl;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 11824kb
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: 226ms
memory: 24172kb
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:
-2095806592
result:
wrong answer 1st numbers differ - expected: '1999991697', found: '-2095806592'