結果
| 問題 |
No.2387 Yokan Factory
|
| コンテスト | |
| ユーザー |
tnakao0123
|
| 提出日時 | 2023-07-25 11:20:47 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 269 ms / 5,000 ms |
| コード長 | 1,535 bytes |
| コンパイル時間 | 606 ms |
| コンパイル使用メモリ | 61,284 KB |
| 実行使用メモリ | 10,804 KB |
| 最終ジャッジ日時 | 2024-10-02 05:42:54 |
| 合計ジャッジ時間 | 4,743 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 35 |
ソースコード
/* -*- coding: utf-8 -*-
*
* 2387.cc: No.2387 Yokan Factory - yukicoder
*/
#include<cstdio>
#include<vector>
#include<queue>
#include<algorithm>
#include<utility>
using namespace std;
/* constant */
const int MAX_N = 100000;
const int MAX_M = 100000;
const long long LINF = 1LL << 62;
/* typedef */
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<pii> vpii;
typedef pair<ll,int> pli;
/* global variables */
vpii nbrs[MAX_N];
int as[MAX_M], bs[MAX_M];
ll ds[MAX_N];
/* subroutines */
ll dijkstra(int n, int b) {
fill(ds, ds + n, LINF);
ds[0] = 0;
priority_queue<pli> q;
q.push(pli(0, 0));
while (! q.empty()) {
auto ue = q.top(); q.pop();
ll ud = -ue.first;
int u = ue.second;
if (ds[u] != ud) continue;
if (u == n - 1) break;
for (auto ve: nbrs[u]) {
int v = ve.first, ei = ve.second;
if (bs[ei] >= b) {
ll vd = ud + as[ei];
if (ds[v] > vd) {
ds[v] = vd;
q.push(pli(-vd, v));
}
}
}
}
return ds[n - 1];
}
/* main */
int main() {
int n, m;
ll x;
scanf("%d%d%lld", &n, &m, &x);
for (int i = 0; i < m; i++) {
int u, v;
scanf("%d%d%d%d", &u, &v, as + i, bs + i);
u--, v--;
nbrs[u].push_back(pii(v, i));
nbrs[v].push_back(pii(u, i));
}
if (dijkstra(n, 1) > x) { puts("-1"); return 0; }
int maxb = *max_element(bs, bs + m);
int b0 = 1, b1 = maxb + 1;
while (b0 + 1 < b1) {
int b = (b0 + b1) / 2;
if (dijkstra(n, b) > x) b1 = b;
else b0 = b;
}
printf("%d\n", b0);
return 0;
}
tnakao0123