比赛 CSP2022提高组 评测结果 AAAAAAAAAAATTTAAATTT
题目名称 假期计划 最终得分 70
用户昵称 zxhhh 运行时间 12.137 s
代码语言 C++ 内存使用 29.95 MiB
提交时间 2022-10-30 08:52:10
显示代码纯文本
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. const int N = 2510, M = 1e4 + 10;
  6. int hd[N], nxt[M * 2], ver[M * 2], idx;
  7. typedef long long LL;
  8.  
  9. int dis[N][N], n, m, k;
  10. LL s[N], res;
  11.  
  12. inline void add (int x, int y) {
  13. ver[++idx] = y;
  14. nxt[idx] = hd[x];
  15. hd[x] = idx;
  16. }
  17.  
  18. void bfs (int st) {
  19. queue <int> q;
  20. dis[st][st] = -1;
  21. q.push(st);
  22. while (q.size()) {
  23. int t = q.front(); q.pop();
  24. if (dis[st][t] >= k) return;
  25. for (int i = hd[t]; i ;i = nxt[i]) {
  26. int y = ver[i];
  27. if (dis[st][t] + 1 < dis[st][y]) {
  28. dis[st][y] = dis[st][t] + 1;
  29. q.push(y);
  30. }
  31. }
  32. }
  33. }
  34.  
  35. int main () {
  36. freopen("csp2022_holiday.in", "r", stdin);
  37. freopen("csp2022_holiday.out", "w", stdout);
  38. memset(dis, 0x3f, sizeof(dis));
  39. scanf("%d%d%d", &n, &m, &k);
  40. for (int i = 2;i <= n;i++) scanf("%lld", &s[i]);
  41. for (int i = 1;i <= m;i++) {
  42. int x, y;
  43. scanf("%d%d", &x, &y);
  44. add(x, y); add(y, x);
  45. }
  46. for (int i = 1;i <= n;i++) bfs(i);
  47. for (int j1 = 2;j1 <= n;j1++) {
  48. if (dis[1][j1] > k) continue;
  49. for (int j2 = 2;j2 <= n;j2++) {
  50. if (j2 == j1 || dis[j1][j2] > k) continue;
  51. for (int j3 = 2;j3 <= n;j3++) {
  52. if (j3 == j2 || j3 == j1 || dis[j3][j2] > k) continue;
  53. for (int j4 = 2;j4 <= n;j4++) {
  54. if (j4 == j1 || j4 == j2 || j4 == j3 || dis[j4][j3] > k || dis[j4][1] > k) continue;
  55. res = max(res, s[j1] + s[j2] + s[j3] + s[j4]);
  56. }
  57. }
  58. }
  59. }
  60. printf("%lld\n", res);
  61. return 0;
  62. }