結果
| 問題 |
No.614 壊れたキャンパス
|
| コンテスト | |
| ユーザー |
ふーらくたる
|
| 提出日時 | 2017-12-13 19:23:45 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 2,003 bytes |
| コンパイル時間 | 1,026 ms |
| コンパイル使用メモリ | 93,332 KB |
| 実行使用メモリ | 814,320 KB |
| 最終ジャッジ日時 | 2024-12-14 10:23:13 |
| 合計ジャッジ時間 | 16,378 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 16 RE * 2 TLE * 2 |
ソースコード
#include <iostream>
#include <map>
#include <utility>
#include <vector>
#include <queue>
#include <algorithm>
#include <tuple>
#include <assert.h>
#include <unordered_map>
using namespace std;
#define int long long
using int64 = long long;
using P = pair<int, int>;
using State = pair<int64, P>;
using Edge = tuple<int, int, int>; // (次の棟, 渡り廊下のある階(自分), 渡り廊下のある階(相手))
const int maxn = 300000;
const int64 inf = (1LL << 50);
int64 N, M, K, S, T;
vector<Edge> G[maxn];
unordered_map<int64, int64> dist;
signed main() {
cin >> N >> M >> K >> S >> T;
assert(2 <= N and N <= 200000);
assert(0 <= M and M <= 200000);
assert(1 <= K and K <= 2e9);
assert(1 <= S and S <= K);
assert(1 <= T and T <= K);
for (int i = 0; i < M; i++) {
int a, b;
int64 c;
cin >> a >> b >> c;
assert(1 <= a and a <= N - 1);
assert(1 <= b and b <= K);
assert(1 <= c and c <= K);
P p1 = {a, b},
p2 = {a + 1, c};
dist[a * K + b] = dist[(a + 1) * K + c] = inf;
G[a].emplace_back(a + 1, b, c);
// G[a + 1].emplace_back(a, c, b);
}
dist[N * K + T] = inf;
priority_queue<State, vector<State>, greater<State>> Q;
Q.push({0, {1, S}});
dist[1 * K + S] = 0;
int64 ans = inf;
while (!Q.empty()) {
auto q = Q.top(); Q.pop();
int64 d = q.first;
int p = q.second.first;
int h = q.second.second;
if (dist[p * K + h] < d) continue;
if (p == N) ans = min(ans, abs(h - T) + d);
for (Edge& e : G[p]) {
int next, cur_s, nxt_s;
tie(next, cur_s, nxt_s) = e;
if (dist[next * K + nxt_s] > abs(cur_s - h) + d) {
dist[next * K + nxt_s] = abs(cur_s - h) + d;
Q.push({dist[next * K + nxt_s], {next, nxt_s}});
}
}
}
if (ans >= inf) cout << -1 << endl;
else cout << ans << endl;
return 0;
}
ふーらくたる