結果

問題 No.1607 Kth Maximum Card
ユーザー tute7627
提出日時 2021-04-28 02:23:23
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 973 bytes
コンパイル時間 2,259 ms
コンパイル使用メモリ 210,020 KB
最終ジャッジ日時 2025-01-21 01:33:10
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2 WA * 1
other AC * 13 WA * 20
権限があれば一括ダウンロードができます

ソースコード

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