yuhaocheng @ 2021-09-13 16:39:53
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e9 + 5;
int n, m, b;
ll d[100001];
bool vis[100001] = {};
map<int, ll> c[100001];
ll f[100001];
void add()
{
int u, v;
ll l;
cin >> u >> v >> l;
if (l >= b) //若减少血量 >= b, 则相当于没有路(不能走)
{
return;
}
if (u == v) //忽略自环
{
return;
}
c[u][v] = l; //双向道路
c[v][u] = l;
}
void init()
{
//缴费最多一次的最小值初始化为INF
for (int i = 0; i <= n; i++)
{
d[i] = INF;
}
//首节点也要收取过路费
d[1] = f[1];
}
void dijkstra()
{
for (int i = 1; i <= n; i++)
{
//找d值最小的节点作为中转节点
int mink = 0;
for (int j = 1; j <= n; j++)
{
if (!vis[j] && d[j] <= d[mink])
{
mink = j;
}
}
vis[mink] = true; //访问
for (auto &iter : c[mink]) //遍历周围节点
{
if (max(d[mink], f[iter.first]) < d[iter.first]) //目标: 缴费最多一次的值尽量小
{
d[iter.first] = max(d[mink], f[iter.first]); //更新
}
}
}
}
void print()
{
if (d[n] == INF) //无法到达终点
{
cout << "AFK" << endl;
}
else
{
cout << d[n] << endl;
}
}
int main()
{
ios::sync_with_stdio(false);
cin >> n >> m >> b;
for (int i = 1; i <= n; i++)
{
cin >> f[i];
}
if(n == 1) {
cout << 0 << endl;
return 0;
}
for (int i = 1; i <= m; i++)
{
add();
}
init();
dijkstra();
print();
return 0;
}