题面
题解
#include<cstdio> #include<iostream> #include<cstring> #include<vector> #include<queue> #define N 90500 #define ri register int #define LL long long using namespace std; int n,s,e,l,r,c; LL dis[N]; vector<int> to[N],len[N]; bool vis[N]; inline void add_edge(int z,int y,int x) { to[z].push_back(y); len[z].push_back(x); } struct node { int u; LL d; bool operator < (const node &rhs) const { return d>rhs.d; } }; priority_queue<node> q; LL dij() { memset(dis,0x3f,sizeof(dis)); dis[s]=0; q.push((node){s,0}); while (!q.empty()) { node cur=q.top(); q.pop(); int x=cur.u; if (vis[x]) continue; vis[x]=1; for (ri i=0;i<to[x].size();i++) { int y=to[x][i]; if (dis[y]>dis[x]+len[x][i]) { dis[y]=dis[x]+len[x][i]; q.push((node){y,dis[y]}); } } } return dis[e+1]; } int main(){ scanf("%d %d %d",&n,&s,&e); for (ri i=1;i<=n;i++) { scanf("%d %d %d",&l,&r,&c); add_edge(l,r+1,c); } for (ri i=1;i<N;i++) add_edge(i,i-1,0); LL ans=dij(); if (ans>1e17) puts("-1"); else printf("%lld ",ans); return 0; }