QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#672839#7883. Takeout DeliveringwzxtslTL 280ms61716kbC++232.6kb2024-10-24 19:27:102024-10-24 19:27:11

Judging History

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

  • [2024-10-24 19:27:11]
  • 评测
  • 测评结果:TL
  • 用时:280ms
  • 内存:61716kb
  • [2024-10-24 19:27:10]
  • 提交

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>dis1){
                q.push({v,w,dis1});
            }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: 7ms
memory: 19932kb

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: 0
Accepted
time: 176ms
memory: 61400kb

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:

1999991697

result:

ok 1 number(s): "1999991697"

Test #3:

score: 0
Accepted
time: 280ms
memory: 61716kb

input:

300000 299999
207226 231742 414945003
84591 210444 175968953
46327 51582 612565723
18773 141119 82562646
76139 286963 762958587
131867 224820 928900783
215240 216181 405340417
144725 290878 195350550
267216 268752 846015171
31413 255927 389339642
45219 147512 489502910
113391 215402 555706684
53359 ...

output:

1989898633

result:

ok 1 number(s): "1989898633"

Test #4:

score: -100
Time Limit Exceeded

input:

300000 299999
1 118488 989720257
1 181002 810258689
1 254222 172925351
1 176703 737330574
1 218306 941887568
1 105741 645573853
1 188490 794789787
1 273997 91455946
1 214929 293300204
1 127289 600097406
1 30589 330284120
1 128954 532459734
1 163729 627033607
1 24073 718818252
1 41571 755054850
1 560...

output:


result: