結果
問題 |
No.3111 Toll Optimization
|
ユーザー |
|
提出日時 | 2025-04-18 21:57:30 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 188 ms / 5,000 ms |
コード長 | 1,633 bytes |
コンパイル時間 | 1,955 ms |
コンパイル使用メモリ | 198,844 KB |
実行使用メモリ | 39,600 KB |
最終ジャッジ日時 | 2025-04-18 21:57:40 |
合計ジャッジ時間 | 8,068 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 70 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:24:42: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 24 | for (int i = 1; i < m + 1; i++) scanf("%d", t + i); | ~~~~~^~~~~~~~~~~~~ main.cpp:27:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 27 | scanf("%d%d", &a, &b); | ~~~~~^~~~~~~~~~~~~~~~
ソースコード
#include <bits/stdc++.h> using namespace std; typedef pair<int, int> pii; typedef pair<long long, int> pli; typedef pair<int, pair<int, int> > piii; typedef long long ll; const int N = 6000086, MOD = 1e9 + 7, INF = 0x3f3f3f3f; ll res; int n, m, cnt, w[N]; int e[N], ne[N], h[N], idx, t[N]; ll d[N]; bool st[N]; void add(int a, int b, int c) { e[idx] = b, ne[idx] = h[a], w[idx] = c, h[a] = idx++; } int main() { int k; cin >> n >> m >> k; memset(h, -1, sizeof(int) * (n + 10) * 4); memset(d, 0x3f, sizeof(ll) * (n + 10) * 4); for (int i = 1; i < m + 1; i++) scanf("%d", t + i); for (int i = 1; i < m + 1; i++) { int a, b; scanf("%d%d", &a, &b); add(a, b, t[i]), add(b, a, t[i]); if (k >= 1) add(a, b + n, 0), add(b, a + n, 0), add(a + n, b + n, t[i]), add(b + n, a + n, t[i]); if (k >= 2) add(a + n, b + n * 2, 0), add(b + n, a + n * 2, 0), add(a + n * 2, b + n * 2, t[i]), add(b + n * 2, a + n * 2, t[i]); if (k == 3) add(a + n * 2, b + n * 3, 0), add(b + n * 2, a + n * 3, 0), add(a + n * 3, b + n * 3, t[i]), add(b + n * 3, a + n * 3, t[i]); } priority_queue<pli, vector<pli>, greater<pli> > q; d[1] = 0; q.push({0, 1}); while (q.size()) { auto u = q.top().second; q.pop(); if (st[u]) continue; st[u] = 1; for (int i = h[u]; ~i; i = ne[i]) { int j = e[i]; if (d[j] > d[u] + w[i]) d[j] = d[u] + w[i], q.push({d[j], j}); } } res = 1e18; for (int i = 0; i <= k; i++) res = min(res, d[n * (i + 1)]); printf("%lld\n", res < 1e18 ? res : -1); return 0; }