結果

問題 No.614 壊れたキャンパス
ユーザー PulmnPulmn
提出日時 2018-07-07 19:53:08
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 518 ms / 2,000 ms
コード長 1,876 bytes
コンパイル時間 1,819 ms
コンパイル使用メモリ 166,632 KB
実行使用メモリ 42,624 KB
最終ジャッジ日時 2023-09-18 14:46:43
合計ジャッジ時間 8,210 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 435 ms
38,932 KB
testcase_09 AC 451 ms
37,440 KB
testcase_10 AC 440 ms
42,624 KB
testcase_11 AC 465 ms
38,632 KB
testcase_12 AC 518 ms
38,724 KB
testcase_13 AC 467 ms
38,884 KB
testcase_14 AC 457 ms
38,928 KB
testcase_15 AC 344 ms
39,988 KB
testcase_16 AC 402 ms
38,968 KB
testcase_17 AC 281 ms
42,000 KB
testcase_18 AC 299 ms
39,508 KB
testcase_19 AC 249 ms
38,304 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}
0