QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#781235 | #7883. Takeout Delivering | pcc1 | WA | 58ms | 27376kb | C++14 | 1.8kb | 2024-11-25 15:21:55 | 2024-11-25 15:21:55 |
Judging History
answer
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
#define int long long
using namespace std;
const int N=1e6+10;
int n,m;
struct node{
int to,nxt,w;
}e[N*2];
int head[N],tot;
void add(int a,int b,int c){
e[++tot].nxt=head[a];
head[a]=tot;
e[tot].to=b;
e[tot].w=c;
}
int ans[N];
struct Node{
int id;
int ans1,ans2;
bool operator <(const Node &p)const{
return p.ans1+p.ans2<ans1+ans2;
}
};
int vis[N];
priority_queue<Node>q;
void dij(){
for(int i=1;i<=n;i++){
ans[i]=1e9+10;vis[i]=0;
}
ans[1]=0;
q.push({1,0,0});
while(!q.empty()){
Node t=q.top();q.pop();
int u=t.id;
if(vis[u])continue;
vis[u]=1;
for(int i=head[u];i;i=e[i].nxt){
int v=e[i].to;
if(vis[v])continue;
int anss1=-1,anss2=-1;
if(e[i].w>t.ans1){
anss2=t.ans1;
anss1=e[i].w;
}
else if(e[i].w>t.ans2){
anss1=t.ans1;
anss2=e[i].w;
}
if(anss1==-1)anss1=t.ans1;
if(anss2==-1)anss2=t.ans2;
if(anss1+anss2<ans[v]){
ans[v]=anss1+anss2;
// cout<<v<<" "<<anss1<<"-="<<anss2<<"\n";
if(!vis[v]){
q.push({v,anss1,anss2});
}
}
}
}
}
signed main(){
ios::sync_with_stdio(0);
cin.tie(0);
cin>>n>>m;
int u,v,w;
int ww=1e9+10;
for(int i=1;i<=m;i++){
cin>>u>>v>>w;
if(u==1&&v==n)ww=min(ww,w);
if(u==n&&v==1)ww=min(ww,w);
add(u,v,w);
add(v,u,w);
}
dij();
cout<<min(ans[n],ww);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 7748kb
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: 58ms
memory: 27376kb
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:
1000000010
result:
wrong answer 1st numbers differ - expected: '1999991697', found: '1000000010'