比赛 |
CSP2022提高组 |
评测结果 |
RRRRRRRRRRRRRRRRRRRR |
题目名称 |
假期计划 |
最终得分 |
0 |
用户昵称 |
小一米 |
运行时间 |
0.395 s |
代码语言 |
C++ |
内存使用 |
53.69 MiB |
提交时间 |
2022-10-30 09:57:52 |
显示代码纯文本
#include<bits/stdc++.h>
#define LL long long
using namespace std;
vector<int> e[2505];
int vis[2505][2505],dis[2505][2505],tmp[2505];
LL s[2505];
queue<int>q;
int n,m,k;
bool cmp(int i,int j){return s[i]>s[j];}
main()
{
scanf("%d%d%d",&n,&m,&k);
for (int i=1;i<n;++i)
scanf("%lld",&s[i+1]);
++k;
for (int u,v,i=1;i<=m;++i)
{
scanf("%d%d",&u,&v);
e[u].push_back(v);
e[v].push_back(u);
}
memset(dis,63,sizeof(dis));
for (int x,i=1;i<=n;++i)
{
dis[i][i]=0;
for (q.push(i);!q.empty();q.pop())
{
x=q.front();
if (dis[i][x]==k) continue;
for (int j=0;j<e[x].size();++j)
if (dis[i][e[x][j]]>k)
dis[i][e[x][j]]=dis[i][x]+1,
// vis[i][++vis[i][0]]=e[x][j],
q.push(e[x][j]);
}
// sort(vis[i]+1,vis[i]+vis[i][0]+1,cmp);
}
for (int j=2;j<=n;++j)
{
for (int i=2;i<=n;++i)
if (i!=j&&dis[1][i]<=k&&dis[i][j]<=k)
vis[j][++vis[j][0]]=i;
sort(vis[j]+1,vis[j]+vis[j][0]+1,cmp);
}
LL ans=0;
for (int i=2;i<=n;++i)
for (int j=i+1;j<=n;++j)
if (dis[i][j]<=k)
for (int k=1;k<=min(2,vis[i][0]);++k)
for (int l=1;l<=min(2,vis[j][0]);++l)
if (vis[i][k]!=j&&vis[j][l]!=i&&vis[i][k]!=vis[j][l])
ans=max(ans,s[i]+s[j]+s[vis[i][k]]+s[vis[j][l]]);
printf("%lld\n",ans);
}