結果
問題 |
No.614 壊れたキャンパス
|
ユーザー |
![]() |
提出日時 | 2017-12-14 21:27:06 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,277 bytes |
コンパイル時間 | 2,172 ms |
コンパイル使用メモリ | 190,904 KB |
実行使用メモリ | 814,724 KB |
最終ジャッジ日時 | 2024-12-14 13:27:04 |
合計ジャッジ時間 | 19,123 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 15 TLE * 5 |
ソースコード
#include <bits/stdc++.h> using namespace std; using state = tuple<long long, int, int>; // (cost, tou, kai) const int MAX = 2e5 + 10; int N, M, S, T; long K; vector<pair<int, long long>> G[MAX]; unordered_map<int, long long> mp[MAX]; //[tou][kai] = minCost int main() { scanf("%d%d%lld%d%d", &N, &M, &K, &S, &T); S--;T--;K--; for (int i = 0; i < M; i++) { int a, b, c; scanf("%d%d%d", &a, &b, &c); a--;b--;c--; G[a].emplace_back(b, c); } priority_queue<state, vector<state>, greater<state>> pq; pq.emplace(0, 0, S); const long long inf = 1e18; long long ans = inf; while (!pq.empty()) { long long cost; int tou, kai; tie(cost, tou, kai) = pq.top(); pq.pop(); if (tou == N - 1) { ans = min(ans, cost + llabs(kai - T)); } if (mp[tou].count(kai)) { continue; } mp[tou][kai] = cost; for (auto&& e : G[tou]) { if (mp[tou + 1].count(e.second) && mp[tou + 1][e.second] <= cost + llabs(e.first - kai)) { continue; } pq.emplace(cost + llabs(e.first - kai), tou + 1, e.second); } } cout << (ans == inf ? -1 : ans) << endl; return 0; }