結果
| 問題 |
No.1320 Two Type Min Cost Cycle
|
| コンテスト | |
| ユーザー |
Kude
|
| 提出日時 | 2020-12-17 12:14:13 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,563 bytes |
| コンパイル時間 | 2,949 ms |
| コンパイル使用メモリ | 203,276 KB |
| 最終ジャッジ日時 | 2025-01-17 02:24:16 |
|
ジャッジサーバーID (参考情報) |
judge2 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 27 WA * 27 TLE * 3 |
ソースコード
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = (n)-1; i >= 0; --i)
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
using ll = long long;
using P = pair<int,int>;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<ll>;
using VVL = vector<VL>;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int T, n, m;
cin >> T >> n >> m;
vector<vector<P>> to(n);
rep(_, m) {
int u, v, w;
cin >> u >> v >> w;
--u, --v;
to[u].emplace_back(v, w);
if (T == 0) to[v].emplace_back(u, w);
}
constexpr ll inf = 1002003004005006007;
ll ans = inf;
rep(s, n) {
VI first_move(n);
VL dist(n, inf);
priority_queue<P, vector<P>, greater<P>> q;
auto push = [&](int v, ll c) {
if (c < dist[v]) {
first_move[v] = false;
dist[v] = c;
q.emplace(c, v);
}
};
for(auto [v, w]: to[s]) {
push(v, w);
first_move[v] = true;
}
while(!q.empty()) {
auto [c, u] = q.top(); q.pop();
if (c != dist[u]) continue;
for(auto [v, w]: to[u]) {
if (first_move[u] && v == s) continue;
push(v, c + w);
}
}
chmin(ans, dist[s]);
}
if (ans == inf) ans = -1;
cout << ans << endl;
}
Kude