rt,https://www.luogu.com.cn/record/176921560,样例三也挂了
# include <bits/stdc++.h>
# define I return
# define AK 0
# define IOI ;
using namespace std;
typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, int> pli;
int n, m, k, x, y, dis[2505][2505];
ll a[2505], maxx;
bitset <2505> vis[2505];
vector <int> v[2505], ma[2505];
priority_queue <pli> pq;
queue <int> q;
void bfs (const int s) {
memset (dis[s], -1, sizeof dis[s]);
q.emplace (s), dis[s][s] = 0;
while (! q.empty ()) {
x = q.front ();
q.pop ();
if (x ^ s) {
vis[s][x] = 1;
if (s ^ 1 && vis[1][x]) {
pq.push ({a[x], x});
if (pq.size () > 5)
pq.pop ();
}
}
if (dis[s][x] > k)
continue ;
for (const int& i : v[x])
if (! ~ dis[s][i])
q.emplace (i), dis[s][i] = dis[s][x] + 1;
}
while (! pq.empty ())
ma[s].emplace_back (pq.top ().second), pq.pop ();
return ;
}
int main () {
ios::sync_with_stdio (0);
cin.tie (0);
cout.tie (0);
cin >> n >> m >> k;
// cerr << n << '\n';
for (int i = 2; i <= n; ++ i)
cin >> a[i];
// cerr << "----------";
while (m --)
cin >> x >> y, v[x].emplace_back (y), v[y].emplace_back (x);
for (int i = 1; i <= n; ++ i)
bfs (i);
// cerr << vis[3][5] << '\n';
// for (int i = 1; i <= n; ++ i) {
// cerr << i << ':';
// for (const int& j : v[i]) cerr << j << ' ';
// cerr << '\n';
// }
for (int i = 2; i <= n; ++ i)
for (int j = 2; j <= n; ++ j)
if (vis[i][j])
for (const int& x : ma[i])
if (x != i && x != j)
for (const int& y : ma[j])
if (x != y && y != i && y != j) //cerr << "1->" << x << "->" << i << "->" << j << "->" << y << "->1:" << a[x] + a[i] + a[j] + a[y] << '\n',
maxx = max (maxx, a[x] + a[i] + a[j] + a[y]);
cout << maxx;
return 0;
}