結果

問題 No.1607 Kth Maximum Card
ユーザー tnakao0123tnakao0123
提出日時 2021-07-20 19:00:00
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 426 ms / 3,500 ms
コード長 1,792 bytes
コンパイル時間 971 ms
コンパイル使用メモリ 101,212 KB
実行使用メモリ 16,464 KB
最終ジャッジ日時 2023-09-24 12:52:39
合計ジャッジ時間 9,013 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
8,216 KB
testcase_01 AC 4 ms
8,200 KB
testcase_02 AC 4 ms
8,200 KB
testcase_03 AC 4 ms
8,308 KB
testcase_04 AC 4 ms
8,152 KB
testcase_05 AC 4 ms
8,132 KB
testcase_06 AC 4 ms
8,228 KB
testcase_07 AC 4 ms
8,152 KB
testcase_08 AC 256 ms
16,428 KB
testcase_09 AC 148 ms
14,976 KB
testcase_10 AC 318 ms
16,464 KB
testcase_11 AC 35 ms
10,320 KB
testcase_12 AC 186 ms
14,584 KB
testcase_13 AC 39 ms
9,388 KB
testcase_14 AC 51 ms
9,804 KB
testcase_15 AC 216 ms
14,328 KB
testcase_16 AC 39 ms
9,584 KB
testcase_17 AC 14 ms
8,568 KB
testcase_18 AC 136 ms
12,496 KB
testcase_19 AC 81 ms
11,064 KB
testcase_20 AC 103 ms
11,552 KB
testcase_21 AC 118 ms
11,916 KB
testcase_22 AC 317 ms
15,376 KB
testcase_23 AC 327 ms
15,588 KB
testcase_24 AC 107 ms
10,496 KB
testcase_25 AC 60 ms
9,836 KB
testcase_26 AC 80 ms
9,884 KB
testcase_27 AC 110 ms
10,640 KB
testcase_28 AC 90 ms
10,220 KB
testcase_29 AC 172 ms
12,644 KB
testcase_30 AC 426 ms
15,260 KB
testcase_31 AC 183 ms
12,116 KB
testcase_32 AC 66 ms
13,576 KB
testcase_33 AC 68 ms
13,604 KB
testcase_34 AC 70 ms
13,608 KB
testcase_35 AC 71 ms
13,552 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

/* -*- coding: utf-8 -*-
 *
 * 1607.cc:  No.1607 Kth Maximum Card - yukicoder
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 200000;
const int INF = 1 << 30;

/* typedef */

typedef long long ll;
typedef queue<int> qi;
typedef pair<int,int> pii;
typedef vector<pii> vpii;

/* global variables */

vpii nbrs[MAX_N];
int ds[MAX_N];
bool used[MAX_N];

/* subroutines */

int bfs01(int n, int x) {
  fill(ds, ds + n, INF);
  fill(used, used + n, false);
  ds[0] = 0;

  qi q0, q1;
  q0.push(0);

  while (! q0.empty() || ! q1.empty()) {
    if (q0.empty()) swap(q0, q1);
    int u = q0.front(); q0.pop();
    if (used[u]) continue;
    if (u == n - 1) break;

    used[u] = true;

    for (auto vc: nbrs[u]) {
      int v = vc.first;
      int vd = ds[u] + (vc.second <= x ? 0 : 1);
      if (ds[v] > vd) {
	ds[v] = vd;
	(vc.second <= x ? q0 : q1).push(v);
      }
    }
  }

  //for (int i = 0; i < n; i++) printf(" %d", ds[i]); putchar('\n');
  //printf("bfs01(%d, %d) = %d\n", n, x, ds[n - 1]);
  return ds[n - 1];
}

/* main */

int main() {
  int n, m, k;
  scanf("%d%d%d", &n, &m, &k);

  int maxc = 0;
  for (int i = 0; i < m; i++) {
    int u, v, c;
    scanf("%d%d%d", &u, &v, &c);
    u--, v--;
    nbrs[u].push_back(pii(v, c));
    nbrs[v].push_back(pii(u, c));
    maxc = max(maxc, c);
  }

  int x0 = -1, x1 = maxc;
  while (x0 + 1 < x1) {
    int x = (x0 + x1) / 2;
    if (bfs01(n, x) >= k) x0 = x;
    else x1 = x;
  }

  printf("%d\n", x1);
  return 0;
}
0