結果
| 問題 |
No.1320 Two Type Min Cost Cycle
|
| コンテスト | |
| ユーザー |
t33f
|
| 提出日時 | 2020-12-17 08:58:41 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 441 ms / 2,000 ms |
| コード長 | 1,219 bytes |
| コンパイル時間 | 918 ms |
| コンパイル使用メモリ | 82,560 KB |
| 最終ジャッジ日時 | 2025-01-17 02:21:40 |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 57 |
ソースコード
#include <queue>
#include <vector>
#include <iostream>
using namespace std;
int main() {
int t, n, m; cin >> t >> n >> m;
vector<pair<int, int> > adj[n];
int weight[m];
for (int i = 0; i < m; i++) {
int u, v, w; cin >> u >> v >> w;
u--; v--;
adj[u].emplace_back(v, i);
if (t == 0) adj[v].emplace_back(u, i);
weight[i] = w;
}
long long ans = 1LL<<60;
for (int u = 0; u < n; u++)
for (auto [v, i] : adj[u]) {
vector<long long> dist(n, 1LL<<60);
priority_queue<pair<long long, int> > pq;
dist[v] = 0;
pq.push({0, v});
while (!pq.empty()) {
long long d = -pq.top().first;
int x = pq.top().second;
pq.pop();
if (d > dist[x]) continue;
for (auto [y, j] : adj[x]) {
if (j == i) continue;
if (dist[y] <= dist[x] + weight[j]) continue;
dist[y] = dist[x] + weight[j];
pq.push({-dist[y], y});
}
}
ans = min(ans, dist[u] + weight[i]);
}
cout << (ans < 1LL<<60 ? ans : -1) << endl;
}
t33f