結果
| 問題 | No.3490 最高経路問題 |
| コンテスト | |
| ユーザー |
pengin_2000
|
| 提出日時 | 2026-04-03 21:46:43 |
| 言語 | C (gcc 15.2.0) |
| 結果 |
AC
|
| 実行時間 | 35 ms / 2,000 ms |
| コード長 | 1,413 bytes |
| 記録 | |
| コンパイル時間 | 1,243 ms |
| コンパイル使用メモリ | 38,716 KB |
| 実行使用メモリ | 6,400 KB |
| 最終ジャッジ日時 | 2026-04-03 21:47:29 |
| 合計ジャッジ時間 | 2,521 ms |
|
ジャッジサーバーID (参考情報) |
judge2_0 / judge3_0 |
| 純コード判定待ち |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 25 |
ソースコード
#include<stdio.h>
int u[100005], v[100005], H[100005];
int h[100005], l;
int comp_h(int a, int b)
{
if (H[h[a]] < H[h[b]])
return 1;
else
return -1;
}
void swap_h(int a, int b)
{
int f = h[a];
h[a] = h[b];
h[b] = f;
return;
}
void push(int ne)
{
h[l] = ne;
int p = l++;
for (; p > 0; p = (p - 1) / 2)
if (comp_h((p - 1) / 2, p) > 0)
swap_h((p - 1) / 2, p);
return;
}
int pop()
{
swap_h(0, --l);
int p = 0;
for (;;)
{
if (2 * p + 2 < l)
{
if (comp_h(2 * p + 1, 2 * p + 2) > 0)
{
if (comp_h(p, 2 * p + 2) > 0)
swap_h(p, 2 * p + 2);
p = 2 * p + 2;
}
else
{
if (comp_h(p, 2 * p + 1) > 0)
swap_h(p, 2 * p + 1);
p = 2 * p + 1;
}
}
else if (2 * p + 1 < l)
{
if (comp_h(p, 2 * p + 1) > 0)
swap_h(p, 2 * p + 1);
p = 2 * p + 1;
}
else
break;
}
return h[l];
}
int par[100005];
int root(int n)
{
if (par[n] != n)
par[n] = root(par[n]);
return par[n];
}
void uni(int a, int b)
{
a = root(a);
b = root(b);
par[a] = b;
return;
}
int main()
{
int n, m;
scanf("%d %d", &n, &m);
int i;
for (i = 0; i < m; i++)
{
scanf("%d %d %d", &u[i], &v[i], &H[i]);
u[i]--;
v[i]--;
}
l = 0;
for (i = 0; i < m; i++)
push(i);
for (i = 0; i < n; i++)
par[i] = i;
while (l > 0)
{
i = pop();
uni(u[i], v[i]);
if (root(0) != root(n - 1))
continue;
printf("%d\n", H[i]);
return 0;
}
printf("NaN\n");
return 0;
}
pengin_2000