QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#671198#7883. Takeout DeliveringwzxtslWA 89ms28812kbC++232.2kb2024-10-24 11:34:492024-10-24 11:34:50

Judging History

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

  • [2024-10-24 11:34:50]
  • 评测
  • 测评结果:WA
  • 用时:89ms
  • 内存:28812kb
  • [2024-10-24 11:34:49]
  • 提交

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{
        //return (x.dis1+x.dis2)<(dis1+dis2);
        return x.dis1<dis1;
    }
}node;
map<PII,int> vis;
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(dist[v]>dis1+dis2+w-min(min(dis1,dis2),w)){
                dist[v]=dis1+dis2+w-min(min(dis1,dis2),w);
                if(w>dis1){
                    q.push({v,w,dis1});
                }else if(w>dis2&&w<dis1){
                    q.push({v,dis1,w});
                }
            }else{
                if(w<dis2){
                    q.push({v,dis1,dis2});
                }else if(w>dis1){
                    q.push({v,w,dis1});
                }
            }
        }
    }
}
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();
	}
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 3ms
memory: 5668kb

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: 89ms
memory: 28812kb

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'