結果
| 問題 |
No.2387 Yokan Factory
|
| コンテスト | |
| ユーザー |
chro_96
|
| 提出日時 | 2023-07-21 22:39:29 |
| 言語 | C (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 1,077 ms / 5,000 ms |
| コード長 | 2,975 bytes |
| コンパイル時間 | 428 ms |
| コンパイル使用メモリ | 31,488 KB |
| 実行使用メモリ | 14,336 KB |
| 最終ジャッジ日時 | 2024-09-22 00:08:34 |
| 合計ジャッジ時間 | 5,063 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 35 |
ソースコード
#include <stdio.h>
#define INF 1000000000000000001LL
typedef struct list {
int v;
long long a;
long long b;
struct list *n;
} list;
void upheap (long long q[][2], int idx) {
int pidx = (idx-1)/2;
if (idx > 0 && q[pidx][0] > q[idx][0]) {
long long s = q[idx][0];
q[idx][0] = q[pidx][0];
q[pidx][0] = s;
s = q[idx][1];
q[idx][1] = q[pidx][1];
q[pidx][1] = s;
upheap(q, pidx);
}
return;
}
void downheap (long long q[][2], int idx, int size) {
long long ch[2] = { INF, INF };
int chidx = -1;
if (2*idx+1 >= size) {
return;
}
ch[0] = q[2*idx+1][0];
if (2*idx+2 < size) {
ch[1] = q[2*idx+2][1];
}
if (ch[1] < ch[0] && ch[1] < q[idx][0]) {
chidx = 2*idx+2;
} else if (ch[0] < q[idx][0]) {
chidx = 2*idx+1;
}
if (chidx > 0) {
long long s = q[idx][0];
q[idx][0] = q[chidx][0];
q[chidx][0] = s;
s = q[idx][1];
q[idx][1] = q[chidx][1];
q[chidx][1] = s;
downheap(q, chidx, size);
}
}
void dequeue (long long q[][2], int *size, long long *res) {
res[0] = q[0][0];
res[1] = q[0][1];
if (*size > 0) {
*size -= 1;
q[0][0] = q[*size][0];
q[0][1] = q[*size][1];
downheap(q, 0, *size);
}
return;
}
int main () {
int n = 0;
int m = 0;
long long x = 0LL;
int u = 0;
int v = 0;
long long a = 0LL;
long long b = 0LL;
int res = 0;
long long ans[2] = { 0LL, 1000000001LL };
list pool[200000] = {};
int used = 0;
list *e[100000] = {};
long long d[100000] = {};
long long q[300000][2] = {};
res = scanf("%d", &n);
res = scanf("%d", &m);
res = scanf("%lld", &x);
for (int i = 0; i < m; i++) {
res = scanf("%d", &u);
res = scanf("%d", &v);
res = scanf("%lld", &a);
res = scanf("%lld", &b);
u--;
v--;
pool[used].v = v;
pool[used].a = a;
pool[used].b = b;
pool[used].n = e[u];
e[u] = pool+used;
used++;
pool[used].v = u;
pool[used].a = a;
pool[used].b = b;
pool[used].n = e[v];
e[v] = pool+used;
used++;
}
while (ans[1]-ans[0] > 1LL) {
long long nxt = (ans[0]+ans[1])/2LL;
int qsize = 0;
for (int i = 0; i < n; i++) {
d[i] = x+1LL;
}
d[0] = 0LL;
q[qsize][0] = 0LL;
q[qsize][1] = 0LL;
upheap(q, qsize);
qsize++;
while (qsize > 0) {
long long tmp[2] = {};
dequeue(q, &qsize, tmp);
if (tmp[0] == d[(int)tmp[1]]) {
list *l = e[(int)tmp[1]];
while (l != NULL) {
if (l->b >= nxt && d[l->v] > tmp[0]+l->a) {
d[l->v] = tmp[0]+l->a;
q[qsize][0] = d[l->v];
q[qsize][1] = (long long)(l->v);
upheap(q, qsize);
qsize++;
}
l = l->n;
}
}
}
if (d[n-1] > x) {
ans[1] = nxt;
} else {
ans[0] = nxt;
}
}
if (ans[0] < 1LL) {
printf("-1\n");
} else {
printf("%lld\n", ans[0]);
}
return 0;
}
chro_96