結果
| 問題 |
No.3111 Toll Optimization
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2025-04-18 21:47:22 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,574 bytes |
| コンパイル時間 | 3,404 ms |
| コンパイル使用メモリ | 199,588 KB |
| 実行使用メモリ | 39,616 KB |
| 最終ジャッジ日時 | 2025-04-18 21:47:32 |
| 合計ジャッジ時間 | 9,457 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 66 WA * 4 |
コンパイルメッセージ
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]);
}
d[1] = 0;
priority_queue<pli, vector<pli>, greater<pli> > q;
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});
}
}
printf("%lld\n", d[n * (k + 1)] < 1e18 ? d[n * (k + 1)] : -1);
return 0;
}