結果
問題 |
No.614 壊れたキャンパス
|
ユーザー |
|
提出日時 | 2017-12-14 14:36:29 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,319 bytes |
コンパイル時間 | 1,294 ms |
コンパイル使用メモリ | 101,400 KB |
最終ジャッジ日時 | 2025-01-05 05:22:13 |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 15 TLE * 5 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:18:27: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 18 | int N, M, K, S, T; scanf("%d%d%d%d%d", &N, &M, &K, &S, &T); | ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ main.cpp:25:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 25 | scanf("%d%d%d", &a, &b, &c); | ~~~~~^~~~~~~~~~~~~~~~~~~~~~
ソースコード
#include <iostream> #include <algorithm> #include <map> #include <queue> using namespace std; using i64 = long long; int a, b, c; map<int, i64> cost[200005]; vector<vector<pair<int, int>>> G; i64 cc; int p, q; i64 _cost; int src, dst; int k; i64 v; int main(void) { constexpr i64 inf = 987654321987654321LL; int N, M, K, S, T; scanf("%d%d%d%d%d", &N, &M, &K, &S, &T); --S, --T; priority_queue<tuple<i64, int, int>, vector<tuple<i64, int, int>>, greater<tuple<i64, int, int>>> pq; pq.emplace(0, 0, S); cost[0][S] = 0; G.resize(N); for(int i=0; i<M; ++i) { scanf("%d%d%d", &a, &b, &c); --a, --b, --c; G[a].emplace_back(b, c); } while(!pq.empty()) { tie(cc, p, q) = pq.top(); pq.pop(); if(!cost[p].count(q)) { continue; } _cost = cost[p][q]; for(auto&& pr : G[p]) { tie(src, dst) = pr; if(!cost[p+1].count(dst)) { cost[p+1][dst] = _cost + abs(q - src); pq.emplace(cost[p+1][dst], p+1, dst); } else if(cost[p+1][dst] > _cost + abs(q - src)) { cost[p+1][dst] = _cost + abs(q - src); pq.emplace(cost[p+1][dst], p+1, dst); } } } i64 mini = inf; for(auto&& kv : cost[N-1]) { mini = min(mini, kv.second + abs(T - kv.first)); } if(mini == inf) { mini = -1; } printf("%lld\n", mini); return 0; }