結果

問題 No.1473 おでぶなおばけさん
ユーザー gotetengoteten
提出日時 2021-12-01 23:08:23
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 159 ms / 2,000 ms
コード長 1,731 bytes
コンパイル時間 1,781 ms
コンパイル使用メモリ 180,640 KB
実行使用メモリ 12,304 KB
最終ジャッジ日時 2023-09-18 09:08:28
合計ジャッジ時間 8,710 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 158 ms
12,208 KB
testcase_03 AC 135 ms
10,964 KB
testcase_04 AC 77 ms
8,008 KB
testcase_05 AC 28 ms
5,108 KB
testcase_06 AC 150 ms
11,664 KB
testcase_07 AC 155 ms
12,300 KB
testcase_08 AC 159 ms
12,196 KB
testcase_09 AC 156 ms
12,260 KB
testcase_10 AC 84 ms
7,432 KB
testcase_11 AC 84 ms
9,200 KB
testcase_12 AC 85 ms
8,152 KB
testcase_13 AC 50 ms
6,236 KB
testcase_14 AC 37 ms
5,152 KB
testcase_15 AC 70 ms
7,544 KB
testcase_16 AC 80 ms
6,824 KB
testcase_17 AC 7 ms
4,376 KB
testcase_18 AC 11 ms
4,376 KB
testcase_19 AC 77 ms
7,984 KB
testcase_20 AC 108 ms
10,232 KB
testcase_21 AC 116 ms
9,788 KB
testcase_22 AC 120 ms
11,452 KB
testcase_23 AC 100 ms
9,860 KB
testcase_24 AC 99 ms
10,056 KB
testcase_25 AC 136 ms
11,068 KB
testcase_26 AC 145 ms
11,228 KB
testcase_27 AC 49 ms
5,924 KB
testcase_28 AC 156 ms
11,972 KB
testcase_29 AC 124 ms
9,904 KB
testcase_30 AC 150 ms
10,812 KB
testcase_31 AC 150 ms
12,304 KB
testcase_32 AC 146 ms
11,756 KB
testcase_33 AC 110 ms
10,560 KB
testcase_34 AC 54 ms
6,936 KB
testcase_35 AC 64 ms
7,172 KB
testcase_36 AC 95 ms
8,668 KB
testcase_37 AC 106 ms
9,660 KB
testcase_38 AC 20 ms
4,732 KB
testcase_39 AC 81 ms
6,956 KB
testcase_40 AC 82 ms
7,052 KB
testcase_41 AC 70 ms
6,300 KB
testcase_42 AC 70 ms
6,452 KB
testcase_43 AC 103 ms
10,844 KB
testcase_44 AC 107 ms
10,588 KB
testcase_45 AC 104 ms
10,652 KB
testcase_46 AC 98 ms
9,292 KB
testcase_47 AC 124 ms
10,412 KB
testcase_48 AC 108 ms
9,900 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

#define rep(i, n) for (int i = 0; i < n; i++)
#define all(x) (x).begin(),(x).end()
const int mod = 998244353;
const int Mod = 1000000007;
const long long INF = 1LL << 60;
using ll = long long;
using ld = long double;
#define v2d(type,H,W,name,value) vector<vector<type>> name(H,vector<type>(W,value));

using plli  = pair<ll ,int>;

struct Edge {
  int to;
  ll w;
  Edge(int to, ll w):to(to),w(w) {}
};

using Graph = vector<vector<Edge>>;

template<class T> bool chmin(T& a, T b){
  if (a>b){
    a=b;
    return true;
  }
  else return false;
}
template<class T> bool chmax(T& a, T b){
  if (a<b){
    a=b;
    return true;
  }
  else return false;
}





int main()
{
  int N,M,s;
  cin >> N >> M;
  s=0;

  Graph G(N+10);
  rep(i,M){
    int a,b,w;
    cin >> a >> b >> w;
    a--;b--;
    G[a].push_back(Edge(b,w));
    G[b].push_back(Edge(a,w));
  }

  vector<ll> dist(N+10,0);
  dist[s]=INF;

  //plli : pair<ll ,int>
  priority_queue<plli> que;
  que.push(make_pair(dist[s],s));

  while(!que.empty()){
    int v=que.top().second;
    ll d=que.top().first;
    que.pop();

    if(d<dist[v]) continue;
    //よって d>=dist[v]
    for(auto e:G[v]){
      if(min(e.w,d)>dist[e.to]){
        dist[e.to]=min(e.w,d);
        que.push(make_pair(dist[e.to],e.to));
      }
    }
  }

  cout << dist[N-1] << " ";

  ll max_w=dist[N-1];



  vector<ll> dist2(N,-1);
  dist2[0]=0;
  
  queue<int> que2;
  que2.push(0);

  while(!que2.empty()){

    int qf=que2.front();
    for(Edge e:G[qf]){
      if(e.w<max_w) continue;
      ll x=e.to;
      if(dist2[x]==-1){
        que2.push(x);
        dist2[x]=dist2[qf]+1;
      }
    }
    que2.pop();
  }

  cout << dist2[N-1] << endl;

}
0