結果

問題 No.614 壊れたキャンパス
ユーザー rickythetarickytheta
提出日時 2017-12-14 01:08:53
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 887 ms / 2,000 ms
コード長 2,317 bytes
コンパイル時間 1,971 ms
コンパイル使用メモリ 167,768 KB
実行使用メモリ 70,888 KB
最終ジャッジ日時 2023-08-21 02:45:43
合計ジャッジ時間 11,536 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 8 ms
21,960 KB
testcase_01 AC 8 ms
21,888 KB
testcase_02 AC 8 ms
21,880 KB
testcase_03 AC 8 ms
21,820 KB
testcase_04 AC 8 ms
22,080 KB
testcase_05 AC 8 ms
21,972 KB
testcase_06 AC 8 ms
21,856 KB
testcase_07 AC 9 ms
21,948 KB
testcase_08 AC 829 ms
70,148 KB
testcase_09 AC 861 ms
68,052 KB
testcase_10 AC 664 ms
69,476 KB
testcase_11 AC 866 ms
70,392 KB
testcase_12 AC 887 ms
70,452 KB
testcase_13 AC 862 ms
70,656 KB
testcase_14 AC 841 ms
70,888 KB
testcase_15 AC 637 ms
69,448 KB
testcase_16 AC 769 ms
69,960 KB
testcase_17 AC 425 ms
69,052 KB
testcase_18 AC 424 ms
62,048 KB
testcase_19 AC 396 ms
60,728 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

// mod
const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

// floating
typedef double Real;
const Real EPS = 1e-11;
#define EQ0(x) (abs(x)<EPS)
#define EQ(a,b) (abs(a-b)<EPS)
typedef complex<Real> P;

int n,m,k,s,t;
int a[252521], b[252521], c[252521];

vi po[252521];
map<pii,int> vrtx;
vector<pii> g[425252];

ll dist[425252];

int main(){
  scanf("%d%d%d%d%d",&n,&m,&k,&s,&t);
  REP(i,m)scanf("%d%d%d",a+i,b+i,c+i);
  po[0].push_back(s);
  po[n-1].push_back(t);
  REP(i,m){
    a[i]--;
    po[a[i]].push_back(b[i]);
    po[a[i]+1].push_back(c[i]);
  }
  int it = 0;
  REP(i,n){
    sort(ALL(po[i]));
    po[i].erase(unique(ALL(po[i])), po[i].end());
    REP(j,po[i].size()){
      vrtx[pii(i,po[i][j])] = it++;
    }
    REP(j,po[i].size()-1){
      int from = vrtx[pii(i,po[i][j])];
      int to = vrtx[pii(i,po[i][j+1])];
      int sa = po[i][j+1] - po[i][j];
      g[from].push_back(pii(to,sa));
      g[to].push_back(pii(from,sa));
    }
  }
  REP(i,m){
    int from = vrtx[pii(a[i], b[i])];
    int to = vrtx[pii(a[i]+1, c[i])];
    g[from].push_back(pii(to,0));
  }
  const ll INF = 1e18;
  REP(i,it)dist[i] = INF;
  priority_queue<pll> Q;
  int start = vrtx[pii(0,s)];
  dist[start] = 0ll;
  Q.push(pll(-dist[start], start));
  while(!Q.empty()){
    ll d = Q.top().first;
    int pos = Q.top().second; Q.pop();
    if(dist[pos] != -d)continue;
    for(pii P : g[pos]){
      int to = P.first;
      int cost = P.second;
      if(dist[pos] + cost < dist[to]){
        dist[to] = dist[pos] + cost;
        Q.push(pll(-dist[to], to));
      }
    }
  }
  int goal = vrtx[pii(n-1,t)];
  if(dist[goal] == INF){
    dist[goal] = -1;
  }
  cout<<dist[goal]<<endl;
  return 0;
}
0