比赛 CSP2022提高组 评测结果 AAAAAAAAAAATTTAAATTT
题目名称 假期计划 最终得分 70
用户昵称 zxhhh 运行时间 12.137 s
代码语言 C++ 内存使用 29.95 MiB
提交时间 2022-10-30 08:52:10
显示代码纯文本
#include <bits/stdc++.h>

using namespace std;

const int N = 2510, M = 1e4 + 10;
int hd[N], nxt[M * 2], ver[M * 2], idx;
typedef long long LL;

int dis[N][N], n, m, k;
LL s[N], res;

inline void add (int x, int y) {
	ver[++idx] = y;
	nxt[idx] = hd[x];
	hd[x] = idx;
}

void bfs (int st) {
	queue <int> q;
	dis[st][st] = -1;
	q.push(st);
	while (q.size()) {
		int t = q.front(); q.pop();
		if (dis[st][t] >= k) return;
		for (int i = hd[t]; i ;i = nxt[i]) {
			int y = ver[i];
			if (dis[st][t] + 1 < dis[st][y]) {
				dis[st][y] = dis[st][t] + 1;
				q.push(y);
			}
		}
	}
}

int main () {
	freopen("csp2022_holiday.in", "r", stdin);
	freopen("csp2022_holiday.out", "w", stdout);
	memset(dis, 0x3f, sizeof(dis));
	scanf("%d%d%d", &n, &m, &k);
	for (int i = 2;i <= n;i++) scanf("%lld", &s[i]);
	for (int i = 1;i <= m;i++) {
		int x, y;
		scanf("%d%d", &x, &y);
		add(x, y); add(y, x);
	}
	for (int i = 1;i <= n;i++) bfs(i);
	for (int j1 = 2;j1 <= n;j1++) {
		if (dis[1][j1] > k) continue;
		for (int j2 = 2;j2 <= n;j2++) {
			if (j2 == j1 || dis[j1][j2] > k) continue;
			for (int j3 = 2;j3 <= n;j3++) {
				if (j3 == j2 || j3 == j1 || dis[j3][j2] > k) continue;
				for (int j4 = 2;j4 <= n;j4++) {
					if (j4 == j1 || j4 == j2 || j4 == j3 || dis[j4][j3] > k || dis[j4][1] > k) continue;
					res = max(res, s[j1] + s[j2] + s[j3] + s[j4]);
				}
			}
		}
	}
	printf("%lld\n", res);
	return 0;
}