結果

問題 No.1607 Kth Maximum Card
ユーザー 👑 tute7627tute7627
提出日時 2021-04-28 02:23:23
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 973 bytes
コンパイル時間 2,407 ms
コンパイル使用メモリ 216,224 KB
実行使用メモリ 18,488 KB
最終ジャッジ日時 2023-09-20 12:31:09
合計ジャッジ時間 8,783 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 WA -
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 WA -
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 308 ms
16,888 KB
testcase_09 AC 239 ms
14,280 KB
testcase_10 AC 305 ms
16,932 KB
testcase_11 AC 61 ms
6,496 KB
testcase_12 AC 227 ms
13,752 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 289 ms
18,488 KB
testcase_23 AC 291 ms
17,816 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 AC 167 ms
10,856 KB
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 AC 142 ms
8,888 KB
testcase_34 WA -
testcase_35 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

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

struct edge{
  int to;
  int c;
};

int main(){
  int n, m, k;
  cin >> n >> m >> k;
  
  vector<vector<edge>>g(n);
  for(int i = 0; i < m; i++){
    int u, v, c;
    cin >> u >> v >> c;
    u--, v--;
    g[u].push_back({v, c});
    g[v].push_back({u, c});
  }
  using ll = long long;
  using pi = pair<ll, int>;
  priority_queue<pi, vector<pi>, greater<pi>>que;
  vector<ll>dist(n, 1e18);
  dist[0] = 0;
  que.emplace(0, 0);
  while(!que.empty()){
    auto [d, v] = que.top();
    que.pop();
    if(dist[v] != d)continue;
    for(auto e:g[v]){
      ll nd = d + e.c;
      if(dist[e.to] > nd){
        dist[e.to] = nd;
        que.emplace(nd, e.to);
      }
    }
  }
  vector<int>cards(k,0);
  int now = n-1;
  while(now){
    for(auto e:g[now]){
      if(dist[e.to] + e.c == dist[now]){
        now = e.to;
        cards.push_back(e.c);
      }
    }
  }
  sort(cards.rbegin(), cards.rend());
  cout << cards[k-1] << endl;
}
0