結果

問題 No.1320 Two Type Min Cost Cycle
ユーザー uenokuuenoku
提出日時 2020-12-17 17:40:39
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 624 ms / 2,000 ms
コード長 1,943 bytes
コンパイル時間 2,281 ms
コンパイル使用メモリ 195,156 KB
実行使用メモリ 4,404 KB
最終ジャッジ日時 2023-10-21 07:00:44
合計ジャッジ時間 11,119 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 1 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 56 ms
4,348 KB
testcase_08 AC 75 ms
4,348 KB
testcase_09 AC 551 ms
4,348 KB
testcase_10 AC 98 ms
4,348 KB
testcase_11 AC 443 ms
4,348 KB
testcase_12 AC 167 ms
4,348 KB
testcase_13 AC 279 ms
4,348 KB
testcase_14 AC 13 ms
4,348 KB
testcase_15 AC 114 ms
4,348 KB
testcase_16 AC 49 ms
4,348 KB
testcase_17 AC 36 ms
4,348 KB
testcase_18 AC 29 ms
4,348 KB
testcase_19 AC 267 ms
4,348 KB
testcase_20 AC 12 ms
4,348 KB
testcase_21 AC 425 ms
4,348 KB
testcase_22 AC 2 ms
4,348 KB
testcase_23 AC 1 ms
4,348 KB
testcase_24 AC 1 ms
4,348 KB
testcase_25 AC 1 ms
4,348 KB
testcase_26 AC 2 ms
4,348 KB
testcase_27 AC 2 ms
4,348 KB
testcase_28 AC 29 ms
4,348 KB
testcase_29 AC 314 ms
4,348 KB
testcase_30 AC 2 ms
4,348 KB
testcase_31 AC 52 ms
4,348 KB
testcase_32 AC 2 ms
4,348 KB
testcase_33 AC 436 ms
4,368 KB
testcase_34 AC 196 ms
4,348 KB
testcase_35 AC 21 ms
4,348 KB
testcase_36 AC 14 ms
4,348 KB
testcase_37 AC 5 ms
4,348 KB
testcase_38 AC 33 ms
4,348 KB
testcase_39 AC 6 ms
4,348 KB
testcase_40 AC 2 ms
4,348 KB
testcase_41 AC 2 ms
4,348 KB
testcase_42 AC 2 ms
4,348 KB
testcase_43 AC 272 ms
4,348 KB
testcase_44 AC 133 ms
4,348 KB
testcase_45 AC 624 ms
4,404 KB
testcase_46 AC 61 ms
4,348 KB
testcase_47 AC 284 ms
4,348 KB
testcase_48 AC 258 ms
4,348 KB
testcase_49 AC 30 ms
4,348 KB
testcase_50 AC 2 ms
4,348 KB
testcase_51 AC 1 ms
4,348 KB
testcase_52 AC 49 ms
4,348 KB
testcase_53 AC 28 ms
4,348 KB
testcase_54 AC 247 ms
4,348 KB
testcase_55 AC 249 ms
4,348 KB
testcase_56 AC 247 ms
4,348 KB
testcase_57 AC 439 ms
4,376 KB
testcase_58 AC 440 ms
4,376 KB
testcase_59 AC 434 ms
4,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function 'int main()':
main.cpp:75:10: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17' [-Wc++17-extensions]
   75 |     auto [U, V, W] = l[i];
      |          ^
main.cpp:77:12: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17' [-Wc++17-extensions]
   77 |       auto [u, v, w] = l[j];
      |            ^

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i, n) for (lli i = 0; i < (n); i++)
#define rrep(i, n) for (lli i = (n)-1; i >= 0; i--)

using namespace std;
struct dijkstra {
    using lli = long long int;
    vector<vector<pair<lli, lli>>> e;
    int n;
    lli inf = 1e18;
    dijkstra(int n) : n(n)
    {
        e.resize(n);
    }
    void add(int a, int b, lli c)
    {
        e[a].push_back(make_pair(b, c));
    }
    void biadd(int a, int b, lli c)
    {
        add(a, b, c);
        add(b, a, c);
    }
    vector<lli> get(int s)
    {
        vector<lli> dist(n, inf);
        dist[s] = 0;
        using p = pair<lli, lli>;
        priority_queue<p, vector<p>, greater<p>> que;
        que.push(make_pair(0, s));
        while (!que.empty()) {
            lli d = que.top().first;
            lli cur = que.top().second;
            que.pop();
            if (dist[cur] < d)
                continue;
            dist[cur] = d;
            for (auto s : e[cur]) {
                lli wei = s.second;
                lli to = s.first;
                if (dist[to] > dist[cur] + wei) {
                    dist[to] = dist[cur] + wei;
                    que.push(make_pair(dist[cur] + wei, to));
                }
            }
        }
        return dist;
    }
};
using lli = long long int;
int main() {
  int t;cin >> t;
  int n,m;cin >> n >> m;
  int u, v, w;
  dijkstra dij(n);
  map<int, map<int, lli>> e;
  vector<tuple<int, int, int>> l;
  rep(i, m){
    cin >> u >> v >> w;
    u--, v--;
    l.emplace_back(u, v, w);

    e[u][v] = w;
    if(t){
      dij.add(u, v, w);
    }
    else {
      e[v][u] = w;
      dij.biadd(v, u, w);
    }
  }
  lli mi = 1e18;
  rep(i, m){
    dijkstra dij(n);
    auto [U, V, W] = l[i];
    rep(j, m) if(j!=i){
      auto [u, v, w] = l[j];
      if(t)
      dij.add(u, v, w);
      else
      dij.biadd(u, v, w);
    }
    mi = min(dij.get(V)[U] + W, mi);
  }
  cout << (mi>=1e18?-1:mi) << endl;

}
0