RT。感谢。
#include <bits/stdc++.h>
using namespace std;
#define srand srand(time(NULL))
#define random(x) rand() % (x)
#define il inline
#define ptc putchar
#define pb push_back
#define reg register
#define mp make_pair
#define R(i, l, r) for (int i = l; i <= r; ++i)
#define debug puts("--------------------------------------------")
typedef __int128 LL;
typedef long long ll;
typedef pair<int, int> PII;
namespace HOOOOOCH {
template <typename T>
il void read(T &x) {
x = 0; T f = 1; char ch;
while (!isdigit(ch = getchar())) f -= (ch == '-') << 1;
while (isdigit(ch)) x = (x << 1) + (x << 3) + (ch & 15), ch = getchar(); x *= f;
}
template <typename T, typename ...L>
il void read(T &x, L &...y) {read(x); read(y...);}
template <typename T>
il void write(T x) {
if (x < 0) ptc('-'), x = -x;
if (x > 9) write(x / 10);
ptc(x % 10 + '0');
}
template <typename T, typename ...L>
il void write(T &x, L &...y) {write(x), ptc(' '); write(y...);}
}
using namespace HOOOOOCH;
#define int ll
const int N = 2505;
int n, m, k, val[N], dis[N][N], ans;
vector <int> E[N];
bool vis[N];
struct node {
int x;
bool operator < (const node &t) const {return val[x] > val[t.x];}
};
vector <int> good[N]; // 合法点
void bfs(int root) {
memset(vis, 0, sizeof vis);
queue <PII> q;
q.push(mp(root, 0));
vis[root] = 1;
priority_queue <node> tmp;
while (q.size()) {
int x = q.front().first, y = q.front().second; q.pop();
dis[root][x] = y;
for (auto v : E[x]) {
if (vis[v]) continue;
vis[v] = 1; q.push(mp(v, y + 1));
}
}
R(i, 2, n) if (i != root && dis[root][i] <= k && dis[1][i] <= k) tmp.push({i});
while (tmp.size() > 3) tmp.pop();
while (tmp.size()) good[root].pb(tmp.top().x), tmp.pop(); // 维护前3大值
}
signed main() {
// freopen("holiday3.in", "r", stdin);
read(n, m, k); ++k;
R(i, 2, n) read(val[i]);
R(i, 1, m) {
int u, v;
read(u, v);
E[u].pb(v), E[v].pb(u);
}
R(i, 1, n) bfs(i);
R(B, 2, n) {
R(C, 2, n) {
if (B == C || dis[B][C] > k) continue;
for (auto A : good[B]) {
for (auto D : good[C]) {
if (A == C || D == B || A == D) continue;
ans = max(ans, val[A] + val[B] + val[C] + val[D]);
}
}
}
}
write(ans);
return 0;
}