結果

問題 No.1473 おでぶなおばけさん
ユーザー bonKotsubonKotsu
提出日時 2021-04-12 23:15:12
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 156 ms / 2,000 ms
コード長 1,299 bytes
コンパイル時間 2,010 ms
コンパイル使用メモリ 180,492 KB
実行使用メモリ 9,972 KB
最終ジャッジ日時 2023-09-11 04:02:38
合計ジャッジ時間 9,537 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,384 KB
testcase_02 AC 156 ms
9,696 KB
testcase_03 AC 132 ms
9,044 KB
testcase_04 AC 77 ms
7,064 KB
testcase_05 AC 28 ms
5,208 KB
testcase_06 AC 150 ms
9,420 KB
testcase_07 AC 155 ms
9,892 KB
testcase_08 AC 152 ms
9,972 KB
testcase_09 AC 147 ms
9,776 KB
testcase_10 AC 84 ms
5,952 KB
testcase_11 AC 83 ms
7,244 KB
testcase_12 AC 84 ms
6,428 KB
testcase_13 AC 51 ms
5,484 KB
testcase_14 AC 37 ms
4,984 KB
testcase_15 AC 71 ms
6,200 KB
testcase_16 AC 80 ms
5,620 KB
testcase_17 AC 7 ms
4,380 KB
testcase_18 AC 12 ms
4,384 KB
testcase_19 AC 78 ms
6,608 KB
testcase_20 AC 108 ms
8,324 KB
testcase_21 AC 112 ms
7,580 KB
testcase_22 AC 116 ms
9,108 KB
testcase_23 AC 96 ms
8,256 KB
testcase_24 AC 95 ms
8,380 KB
testcase_25 AC 136 ms
9,120 KB
testcase_26 AC 143 ms
8,840 KB
testcase_27 AC 48 ms
5,488 KB
testcase_28 AC 152 ms
9,632 KB
testcase_29 AC 121 ms
7,824 KB
testcase_30 AC 147 ms
8,672 KB
testcase_31 AC 139 ms
9,576 KB
testcase_32 AC 141 ms
9,500 KB
testcase_33 AC 109 ms
8,276 KB
testcase_34 AC 52 ms
6,236 KB
testcase_35 AC 63 ms
6,356 KB
testcase_36 AC 92 ms
6,924 KB
testcase_37 AC 107 ms
8,132 KB
testcase_38 AC 20 ms
4,684 KB
testcase_39 AC 82 ms
5,672 KB
testcase_40 AC 81 ms
5,672 KB
testcase_41 AC 70 ms
5,520 KB
testcase_42 AC 70 ms
5,440 KB
testcase_43 AC 99 ms
8,236 KB
testcase_44 AC 99 ms
8,240 KB
testcase_45 AC 100 ms
8,336 KB
testcase_46 AC 96 ms
7,788 KB
testcase_47 AC 120 ms
8,576 KB
testcase_48 AC 106 ms
8,004 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define rep(i, n) for (int i = 0; i < (n); i++)
#define P pair<int, int>

struct Edge {
  int to, w;

  Edge(int to, int w) : to(to), w(w) {}

};

int main() {
  int n, m;
  cin >> n >> m;

  vector<vector<Edge>> G(n);
  rep(i, m) {
    int s, t, d;
    cin >> s >> t >> d;
    s--, t--;
    G[s].push_back(Edge(t, d));
    G[t].push_back(Edge(s, d));
  }

  vector<int> weight(100005, 0); 
  const int INF = 1001001001;
  weight[0] = INF;
  priority_queue<P, vector<P>> q;
  q.push({INF,0});

  while(!q.empty()) {
    int w = q.top().first, v = q.top().second; q.pop();
    rep(j, G[v].size()) {
      Edge e = G[v][j];
      int nv = e.to, cost = e.w;
      if (min(w, cost) > weight[nv]) {
        weight[nv] = min(w,cost);
        q.push({weight[nv], nv});
      }
    }
  }
  int ans_w = weight[n-1];
  
  vector<int> dist(100004, INF);
  dist[0] = 0;
  queue<int> que;
  que.push(0);
  while(!que.empty()) {
    int v = que.front(); que.pop();
    rep(i, G[v].size()) {
      Edge e = G[v][i];
      int nv = e.to, cost = e.w;
      if (dist[nv] != INF) continue;
      if (cost < ans_w) continue;
      dist[nv] = dist[v]+1;
      que.push(nv);
    }
  }
  int ans_d = dist[n-1];
  cout << ans_w << " " << ans_d << endl;
}
0