結果
| 問題 | No.3653 Space-Time Courier |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-07-21 22:01:20 |
| 言語 | C++23(gcc16) (gcc 16.1.0 + boost 1.90.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,153 bytes |
| 記録 | |
| コンパイル時間 | 1,575 ms |
| コンパイル使用メモリ | 200,320 KB |
| 実行使用メモリ | 6,272 KB |
| 最終ジャッジ日時 | 2026-08-28 21:01:53 |
| 合計ジャッジ時間 | 5,465 ms |
|
ジャッジサーバーID (参考情報) |
judge1_0 / judge3_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 15 WA * 13 |
ソースコード
#include <iostream>
#include <vector>
#include <queue>
using namespace std;
const long long INF = 1e18;
struct Edge {
int to;
long long cost;
};
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int N, M;
if (!(cin >> N >> M)) return 0;
vector<long long> P(N + 1);
for (int i = 1; i <= N; ++i) {
cin >> P[i];
}
vector<vector<Edge>> adj(N + 1);
for (int i = 0; i < M; ++i) {
int u, v;
long long t;
cin >> u >> v >> t;
adj[u].push_back({v, t});
}
long long min_total_cost = INF;
long long min_count = 0;
for (int start = 1; start <= N; ++start) {
vector<long long> dist(N + 1, INF);
vector<int> hops(N + 1, 0); // 始点からの辺の数
vector<bool> in_queue(N + 1, false);
queue<int> q;
dist[start] = 0;
q.push(start);
in_queue[start] = true;
while (!q.empty()) {
int u = q.front();
q.pop();
in_queue[u] = false;
// ホップ数が 20 を超えたらそれ以上深い探索をしない(嘘!)
if (hops[u] > 20) continue;
for (auto& edge : adj[u]) {
int v = edge.to;
long long weight = edge.cost;
if (dist[u] + weight < dist[v]) {
dist[v] = dist[u] + weight;
hops[v] = hops[u] + 1;
if (!in_queue[v]) {
q.push(v);
in_queue[v] = true;
}
}
}
}
for (int v = 1; v <= N; ++v) {
if (start == v || dist[v] == INF) continue;
long long current_cost = dist[v] + P[start] + P[v];
if (current_cost < min_total_cost) {
min_total_cost = current_cost;
min_count = 1;
} else if (current_cost == min_total_cost) {
min_count++;
}
}
}
if (min_total_cost == INF) cout << -1 << "\n";
else cout << min_total_cost << " " << min_count << "\n";
return 0;
}