結果
| 問題 | No.3653 Space-Time Courier |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-07-21 22:03:48 |
| 言語 | C++23(gcc16) (gcc 16.1.0 + boost 1.90.0) |
| 結果 |
WA
(最新)
AC
(最初)
|
| 実行時間 | - |
| コード長 | 2,653 bytes |
| 記録 | |
| コンパイル時間 | 2,145 ms |
| コンパイル使用メモリ | 216,008 KB |
| 実行使用メモリ | 6,272 KB |
| 最終ジャッジ日時 | 2026-08-28 21:02:01 |
| 合計ジャッジ時間 | 11,054 ms |
|
ジャッジサーバーID (参考情報) |
judge2_0 / judge3_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 27 WA * 1 |
ソースコード
#include <iostream>
#include <vector>
#include <deque>
#include <algorithm>
#include <random>
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});
}
// 辺の評価順をランダムにして、特定のキラーケースを回避する
mt19937 rng(42);
for (int i = 1; i <= N; ++i) {
shuffle(adj[i].begin(), adj[i].end(), rng);
}
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<bool> in_queue(N + 1, false);
deque<int> dq;
dist[start] = 0;
dq.push_back(start);
in_queue[start] = true;
int op_count = 0;
// ループ回数の上限(これを超えたら、その時点の暫定解で妥協する)
const int OP_LIMIT = 150000;
while (!dq.empty()) {
int u = dq.front();
dq.pop_front();
in_queue[u] = false;
op_count++;
if (op_count > OP_LIMIT) break; // TLE逃れ
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;
if (!in_queue[v]) {
// SLF (Small Label First) 最適化
if (!dq.empty() && dist[v] < dist[dq.front()]) {
dq.push_front(v);
} else {
dq.push_back(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;
}