QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#672843 | #7883. Takeout Delivering | wzxtsl | WA | 101ms | 42636kb | C++23 | 2.5kb | 2024-10-24 19:28:22 | 2024-10-24 19:28:22 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define fast ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define For(i,j,k) for (int i=(j);i<=(k);i++)
#define rof(i,j,k) for (int i=(j);i>=(k);i--)
#define ull unsigned long long
#define lowbit(x) ((x)&(-(x)))
#define PII pair<int,int>
#define int long long
#define endl "\n"
#define ls rt<<1
#define rs rt<<1|1
typedef long long ll;
const int mod = 998244353;
const double eps = 1e-9;
const int N=2e6+7;
int n,m;
typedef struct edge{
int pos;
int w;
}edge;
vector<edge> connects[2000100];
void add_edge(int u,int v,int w){
connects[u].push_back({v,w});
connects[v].push_back({u,w});
return ;
}
typedef struct node{
int pos;
int dis1;
int dis2;
bool operator<(const node &x) const{
if(x.dis1!=dis2) return x.dis1<dis2;
else return (x.dis1+x.dis2)<(dis1+dis2);
//return x.dis1<dis1;
}
}node;
map<int,int> vis[300005];
int dist[300005];
void Dijikstra(int start){
dist[start]=0;
priority_queue<node> q;
q.push({start,0,0});
while(!q.empty()){
int pos=q.top().pos;
int dis1=q.top().dis1;
int dis2=q.top().dis2;
if(dis1<dis2) swap(dis1,dis2);
q.pop();
if(vis[pos][dis1+dis2]) continue;
vis[pos][dis1+dis2]=1;
for(int i=0;i<connects[pos].size();i++){
int v=connects[pos][i].pos;
int w=connects[pos][i].w;
// if(vis[pos][v]) continue;
// vis[pos][v]=1;
if(dist[v]>dis1+dis2+w-min(min(dis1,dis2),w)){
dist[v]=dis1+dis2+w-min(min(dis1,dis2),w);
}
// if(w<dis2){
// q.push({v,dis1,dis2});
// }else if(w>dis1){
// q.push({v,w,dis1});
// }else if(w>dis2&&w<dis1){
// q.push({v,dis1,w});
// }
if(dis1==0&&dis2==0){
q.push({v,w,0});
}else if(dis1!=0&&dis2==0){
q.push({v,dis1,w});
}else if(w<dis2){
q.push({v,dis1,dis2});
}else if(w>dis2&&w<dis1){
q.push({v,dis1,w});
}
}
}
}
void solve(){
cin>>n>>m;
while(m--){
int u,v,w;
cin>>u>>v>>w;
add_edge(u,v,w);
}
for(int i=1;i<=n;i++) dist[i]=1e18;
Dijikstra(1);
cout<<dist[n]<<endl;
}
signed main(){
fast;
int t=1;
//cin>>t;
while(t--){
solve();
}
}
详细
Test #1:
score: 100
Accepted
time: 3ms
memory: 19952kb
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: 101ms
memory: 42636kb
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:
1000000000000000000
result:
wrong answer 1st numbers differ - expected: '1999991697', found: '1000000000000000000'