結果
| 問題 | No.614 壊れたキャンパス | 
| コンテスト | |
| ユーザー |  Pulmn | 
| 提出日時 | 2018-07-07 19:53:08 | 
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 535 ms / 2,000 ms | 
| コード長 | 1,876 bytes | 
| コンパイル時間 | 1,755 ms | 
| コンパイル使用メモリ | 179,596 KB | 
| 実行使用メモリ | 42,816 KB | 
| 最終ジャッジ日時 | 2024-07-05 05:32:38 | 
| 合計ジャッジ時間 | 8,689 ms | 
| ジャッジサーバーID (参考情報) | judge2 / judge4 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 20 | 
ソースコード
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-8;
const ll mod=1e9+7;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};
class Graph{
	private:
	int n;
	vvp g;
	public:
	ll DIJ(int s,int t){
		priority_queue<pll> q;
		vl d(n,INF);
		d[s]=0;
		q.push({0,s});
		while(!q.empty()){
			pll p=q.top();
			q.pop();
			ll v=p.second;
			if(d[v]<-p.first) continue;
			for(auto i:g[v]){
				ll u=i.first,D=d[v]+i.second;
				if(d[u]>D){
					d[u]=D;
					q.push({-D,u});
				}
			}
		}
		return d[t];
	}
	Graph(int v){
		n=v;
		g=vvp(v);
	}
	void add_edge(int s,int t,int c){
		g[s].push_back({t,c});
	}
};
int n,m,h,u,v;
vvi a;
vi x,y,z,s;
int f(int A,int B){
	return lower_bound(a[A].begin(),a[A].end(),B)-a[A].begin()+s[A];
}
int main(){
	cin>>n>>m>>h>>u>>v;
	a=vvi(n);
	s=vi(n);
	a[0].push_back(u);
	a[n-1].push_back(v);
	x=y=z=vi(m);
	Graph g(2*m+2);
	for(int i=0;i<m;i++){
		int A,B,C;
		cin>>A>>B>>C;
		a[A-1].push_back(B);
		a[A].push_back(C);
		x[i]=A,y[i]=B,z[i]=C;
	}
	for(int i=0;i<n;i++){
		if(i) s[i]=s[i-1]+a[i-1].size();
		sort(a[i].begin(),a[i].end());
		for(int j=1;j<a[i].size();j++){
			g.add_edge(s[i]+j-1,s[i]+j,a[i][j]-a[i][j-1]);
			g.add_edge(s[i]+j,s[i]+j-1,a[i][j]-a[i][j-1]);
		}
	}
	for(int i=0;i<m;i++){
		g.add_edge(f(x[i]-1,y[i]),f(x[i],z[i]),0);
	}
	ll res=g.DIJ(f(0,u),f(n-1,v));
	cout<<(res==INF?-1:res)<<endl;
}
            
            
            
        