結果
| 問題 | No.3653 Space-Time Courier |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-09-06 20:06:16 |
| 言語 | C++23(gcc16) (gcc 16.1.0 + boost 1.92.0 + ACL) |
| 結果 |
TLE
不安定
|
| 実行時間 | - |
| コード長 | 2,141 bytes |
| 記録 | |
| コンパイル時間 | 4,824 ms |
| コンパイル使用メモリ | 262,696 KB |
| 実行使用メモリ | 6,272 KB |
| 最終ジャッジ日時 | 2026-09-06 20:06:45 |
| 合計ジャッジ時間 | 26,631 ms |
|
ジャッジサーバーID (参考情報) |
judge3_0 / judge1_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 25 TLE * 3 |
ソースコード
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <print>
using namespace std;
const long long INF = 1e18;
struct Edge {
int to;
long long weight;
};
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
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);
vector<int> in_degree(n + 1, 0);
for (int i = 0; i < m; ++i) {
int u, v;
long long t;
cin >> u >> v >> t;
adj[u].push_back({v, t});
in_degree[v]++;
}
long long min_cost = INF;
long long ways = 0;
// N <= 2500, M <= 5000 なので、各始点からSPFA (Shortest Path Faster Algorithm) を回す
for (int start = 1; start <= n; ++start) {
vector<long long> dist(n + 1, INF);
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;
for (const auto& edge : adj[u]) {
if (dist[u] + edge.weight < dist[edge.to]) {
dist[edge.to] = dist[u] + edge.weight;
if (!in_queue[edge.to]) {
q.push(edge.to);
in_queue[edge.to] = true;
}
}
}
}
// コストの最小値とその数を更新
for (int target = 1; target <= n; ++target) {
if (start == target || dist[target] == INF) continue;
long long current_cost = dist[target] + p[start] + p[target];
if (current_cost < min_cost) {
min_cost = current_cost;
ways = 1;
} else if (current_cost == min_cost) {
ways++;
}
}
}
if (min_cost == INF) {
std::println("-1");
} else {
std::println("{} {}", min_cost, ways);
}
return 0;
}