题意大概让算t秒每一秒的最短路和,每条边每秒dis++;
dp算距离dis[i][j]:1到i点走j条边的最短路O(n(n+ m));
单调栈维护个上凸;
等差数列n^2求解;
代码:
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<queue>
#include<vector>
using namespace std;
long long mod=1e9+7;
int head[5505],tot,to[15005],val[15005],nex[15005];
int dis[5505][5505];
int n,m,t;
int inf=99999999;
long long ans;
void add(int x,int y,int v)
{
int tmp=head[x];
head[x]=++tot;
to[tot]=y;
val[tot]=v;
nex[tot]=tmp;
}
void cal()
{
for(int i=1;i<=n;i++)
for(int j=0;j<=n;j++)
dis[i][j]=inf;
dis[1][0]=0;
for(int i=0;i<n-1;i++)
for(int j=1;j<=n;j++)
if(dis[j][i]<inf)
{
for(int now=head[j];now!=-1;now=nex[now])
{
int next=to[now];
if(dis[next][i+1]==inf||dis[next][i+1]>dis[j][i]+val[now])
{
dis[next][i+1]=dis[j][i]+val[now];
}
}
}
}
int q[5005],from[5005];
long long C(int k0,int a0,int k1,int a1,int k2,int a2) //locate x cordinate
{
return (long long)(a0-a1)*(k2-k0)-(long long)(a0-a2)*(k1-k0);
}
void solve(int x)
{
tot=0;
for(int i=n-1;i>=0;i--)
{
if(dis[x][i]==inf) continue;
while(tot>=2&&C(q[tot-1],dis[x][q[tot-1]],q[tot],dis[x][q[tot]],i,dis[x][i])>=0) tot--;
q[++tot]=i;
}
from[1]=0;
for(int i=2;i<=tot;i++)
from[i]=(dis[x][q[i]]-dis[x][q[i-1]]+q[i-1]-q[i]-1)/(q[i-1]-q[i]); //trans to int(up)a
int to=t+1;
for(int i=1;i<=tot;i++) from[i]=max(0,from[i]);
for(int i=tot;i>=1;i--)
{
if(from[i]>=to) continue;
ans=(ans+(long long)(dis[x][q[i]])*(to-from[i])%mod)%mod;
ans=(ans+(long long )(to+from[i]-1)* ((to-from[i])/2)%mod*q[i])%mod;
to=from[i];
}
}
int main()
{
int aa,bb,cc;
scanf("%d%d%d",&n,&m,&t);
memset(head,-1,sizeof(head));
for(int i=1;i<=m;i++)
{
scanf("%d%d%d",&aa,&bb,&cc);
add(aa,bb,cc);
add(bb,aa,cc);
}
cal();
for(int i=1;i<=n;i++)
solve(i);
cout<<(ans+mod)%mod<<endl;
}