結果
| 問題 |
No.1320 Two Type Min Cost Cycle
|
| コンテスト | |
| ユーザー |
trineutron
|
| 提出日時 | 2020-12-17 11:09:42 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 1,391 bytes |
| コンパイル時間 | 2,215 ms |
| コンパイル使用メモリ | 207,052 KB |
| 最終ジャッジ日時 | 2025-01-17 02:23:40 |
|
ジャッジサーバーID (参考情報) |
judge3 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 RE * 1 |
| other | AC * 13 WA * 16 RE * 28 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
using weight = int64_t;
using edge = pair<int, weight>;
using vertice = vector<edge>;
using graph = vector<vertice>;
using cost = tuple<int64_t, int, int>;
int main() {
constexpr int64_t inf = 1e18;
int t, n, m;
cin >> t >> n >> m;
assert(t == 0);
graph to(n);
for (int i = 0; i < m; i++) {
int u, v, w;
cin >> u >> v >> w;
u--; v--;
to.at(u).emplace_back(v, w);
if (t == 0) {
to.at(v).emplace_back(u, w);
}
}
int64_t ans = inf;
for (int i = 0; i < n; i++) {
vector<int64_t> d(n, inf);
priority_queue<cost, vector<cost>, greater<cost>> q;
q.emplace(0, i, -1);
while (not q.empty()) {
auto [dist, v, from] = q.top();
q.pop();
if (d.at(v) <= dist) continue;
if (dist) {
d.at(v) = dist;
}
for (auto next : to.at(v)) {
auto [next_v, next_w] = next;
if (next_v == from) continue;
int64_t next_dist = dist + next_w;
if (d.at(next_v) <= next_dist) continue;
q.emplace(next_dist, next_v, v);
}
}
ans = min(ans, d.at(i));
}
if (ans == inf) {
cout << -1 << endl;
} else {
cout << ans << endl;
}
}
trineutron