就是求前k短路的权值和<=E
据说卡STL的priority_queue 那么我用STL的heap好了
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<cstring>
#define cl(x) memset(x,0,sizeof(x))
#define V G[p].v
using namespace std;
const int M=200005;
const int N=5005;
struct edge{
int u,v; double w;
int next;
};
edge G[M<<1];
int head[N],inum;
inline void add(int u,int v,double w,int p){
G[p].u=u; G[p].v=v; G[p].w=w; G[p].next=head[u]; head[u]=p;
}
const int ND=1000005;
int Q[ND],l,r;
int ins[N];
double dis[N];
int n,m,ans; double E;
int iu[M],iv[M]; double iw[M];
inline void SPFA(int S){
int u;
for (int i=1;i<=n;i++) dis[i]=1e130,ins[i]=0;
l=r=-1;
dis[S]=0; Q[(++r)%ND]=S; ins[S]=1;
while (l!=r){
u=Q[(++l)%ND]; ins[u]=0;
for (int p=head[u];p;p=G[p].next)
if (dis[V]>dis[u]+G[p].w)
{
dis[V]=dis[u]+G[p].w;
if (!ins[V])
Q[(++r)%ND]=V,ins[V]=1;
}
}
}
struct abcd{
int u;
double g,f;
abcd(int u=0,double g=0,double f=0):u(u),g(g),f(f) { }
bool operator < (const abcd &B) const{
return f>B.f;
}
}H[2000005];
int end;
inline void push(abcd x){
H[++end]=x; push_heap(H+1,H+end+1);
}
inline abcd pop(){
pop_heap(H+1,H+end+1);
return H[end--];
}
inline void A_star(){
abcd now;
push(abcd(1,0,dis[1]));
while (end){
now=pop();
for (int p=head[now.u];p;p=G[p].next)
push(abcd(V,now.g+G[p].w,now.g+G[p].w+dis[V]));
if (now.u==n){
E-=now.f;
if (E<0) return;
ans++;
}
}
}
int main()
{
freopen("t.in","r",stdin);
freopen("t.out","w",stdout);
scanf("%d%d%lf",&n,&m,&E);
for (int i=1;i<=m;i++)
scanf("%d%d%lf",iu+i,iv+i,iw+i),add(iv[i],iu[i],iw[i],++inum);
SPFA(n);
inum=0; cl(head); cl(G);
for (int i=1;i<=m;i++) add(iu[i],iv[i],iw[i],++inum);
A_star();
printf("%d\n",ans);
return 0;
}