在第73行的sort函数,在蒟蒻在CMP直接没用的情况下能有80pts
属实离谱过度
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cmath>
#include<vector>
#include<queue>
using namespace std;
#define ll long long
#define ull unsigned long long
#define ldouble long double
#define uint unsigned int
struct EDGE
{
ll to,Next;
}edge[1000005];
ll head[2505],total;
inline void add_Edge(ll u,ll v)
{
edge[++total]=EDGE{v,head[u]};head[u]=total;
}
ll dis[2505][2505],n,m,K;
ll pointw[2505];
ll pre[2505][5];
ll ans;
inline void bfs(ll s)
{
queue<int>q;
q.push(s);
dis[s][s]=-1;
int pos;
while (!q.empty())
{
pos=q.front();q.pop();
if (dis[s][pos]>=K) break;
for (int e=head[pos],Next;e;e=edge[e].Next)
{
Next=edge[e].to;
if (dis[s][Next]>dis[s][pos]+1)
{
dis[s][Next]=dis[s][pos]+1;
q.push(Next);
}
}
}
}
bool CMP(int a,int b)
{
return pointw[a]>pointw[b];
}
int main()
{
memset(dis,0x3f,sizeof(dis));
scanf("%lld %lld %lld",&n,&m,&K);
for (int i=2;i<=n;i++)
scanf("%lld",&pointw[i]);
for (ll i=1,x,y,z;i<=m;i++)
{
scanf("%lld %lld",&x,&y);
add_Edge(x,y);add_Edge(y,x);
}
int temp[2505],tot=0;
for (int i=1;i<=n;i++) bfs(i);
for (int i=2;i<=n;i++)
{
tot=0;
for (int j=2;j<=n;j++)
{
if (i==j) continue;
if (dis[i][j]<=K&&dis[j][1]<=K)
temp[++tot]=j;
}
sort(temp+1,temp+1+tot,CMP);//正确写法
//sort(temp+1,temp+1+tot);//这样可以有80pts?????
if (tot<4)
{
for (int j=1;j<=tot;j++)
pre[i][j]=temp[j];
for (int j=tot+1;j<=4;j++)
pre[i][j]=0;
}
else
for (int j=1;j<=4;j++)
pre[i][j]=temp[j];
}
/*for (int i=2;i<=n;i++)
{
cerr<<i<<endl;
for (int j=1;j<=4;j++)
cerr<<pre[i][j]<<' ';
cerr<<endl;
}
cerr<<endl;*/
for (int i=2;i<=n;i++)
{
for (int j=2;j<=n;j++)
{
if (i==j) continue;
if (dis[i][j]>K) continue;
for (int k=1;k<=4;k++)
{
if (pre[i][k]==0) continue;
for (int l=1;l<=4;l++)
{
if (pre[j][l]==0) continue;
if (pre[i][k]!=j&&pre[i][k]!=pre[j][l]&&pre[j][l]!=i)
ans=max(ans,pointw[i]+pointw[j]+pointw[pre[i][k]]+pointw[pre[j][l]]);
}
}
}
}
printf("%lld",ans);
return 0;
}