有大佬知道哪里错了吗?
#include <bits/stdc++.h>
#define P pair<long long, int>
#define fi first
#define se second
#define pb push_back
using namespace std;
typedef long long ll;
template <typename T> inline void rd(T &x) {
x = 0; T f = 1; char ch = getchar();
while (ch < '0' || ch > '9') {if (ch == '-') f = -1; ch = getchar();}
while (ch >= '0' && ch <= '9') {x = (x << 1) + (x << 3) + (ch ^ 48); ch = getchar();}
x *= f;
}
template <typename T> inline void write(T x) {
if (x < 0) {putchar('-'); x = -x;}
if (x >= 10) write(x / 10);
putchar(x % 10 + '0');
}
template <typename T> inline T ckmax(T x, T y) {return x > y ? x : y;}
template <typename T> inline T ckmin(T x, T y) {return x < y ? x : y;}
template <typename T> inline T abv(T x) {return x < 0 ? -x : x;}
const int N = 2520;
const int INF = 0x3f3f3f3f;
const ll Mod = 1e9 + 7;
int n, m, k;
int a[N], d[N][N];
set<P> st[N];
vector<int> G[N];
bool vis[N];
void bfs(int s) {
memset(vis, 0, sizeof(vis));
queue<int> q;
q.push(s);
d[s][s] = -1;
while (!q.empty()) {
int u = q.front(); q.pop();
if (vis[u]) continue;
vis[u] = 1;
for (auto v : G[u]) {
if (d[s][v] > d[s][u] + 1) {
d[s][v] = d[s][u] + 1;
q.push(v);
}
}
}
}
int main() {
memset(d, INF, sizeof(d));
rd(n); rd(m); rd(k);
for (int i = 2; i <= n; i++) rd(a[i]);
for (int i = 1; i <= m; i++) {
int u, v;
rd(u); rd(v);
G[u].pb(v);
G[v].pb(u);
}
for (int i = 1; i <= n; i++) bfs(i);
for (int i = 2; i <= n; i++) {
if (d[1][i] > k) continue;
for (int j = 2; j <= n; j++) {
if (d[i][j] > k || i == j) continue;
st[j].insert(P(a[i] + a[j], i));
if (st[j].size() > 3) st[j].erase(*st[j].begin());
}
}
ll ans = 0;
for (int i = 2; i <= n; i++) {
for (int j = i + 1; j <= n; j++) {
if (d[i][j] > k) continue;
for (auto x : st[i]) {
for (auto y : st[j]) {
if (!(x.se != j && x.se != y.se && i != y.se)) continue;
ans = ckmax(ans, x.fi + y.fi);
}
}
}
}
write(ans);
return 0;
}