1975: [Sdoi2010]魔法猪学院
裸题...
被double坑死了
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>
using namespace std;
typedef long long ll;
#define pdi pair<double, int>
#define fir first
#define sec second
const int N = 5005, M = 2e5+5;
inline int read(){
char c=getchar(); int x=0,f=1;
while(c<'0'||c>'9') {if(c=='-')f=-1;c=getchar();}
while(c>='0'&&c<='9') {x=x*10+c-'0';c=getchar();}
return x*f;
}
int n, m, u, v, s, t; double en, w;
namespace I {
struct edge {int v, ne; double w;} e[M];
int cnt, h[N];
inline void ins(int u, int v, double w) {
e[++cnt] = (edge){v, h[u], w}; h[u] = cnt;
}
priority_queue<pdi, vector<pdi>, greater<pdi> > q;
int vis[N];
void dij(int s, int t, double *d) {
for(int i=1; i<=n; i++) d[i] = 1e15, vis[i] = 0;
d[s] = 0; q.push(make_pair(0, s));
while(!q.empty()) {
int u = q.top().sec; q.pop();
if(vis[u]) continue; vis[u] = 1;
for(int i=h[u];i;i=e[i].ne) {
int v = e[i].v;
if(d[v] > d[u] + e[i].w)
d[v] = d[u] + e[i].w, q.push(make_pair(d[v], v));
}
}
}
}
struct edge {int v, ne; double w;} e[M];
int cnt, h[N];
inline void ins(int u, int v, double w) {
e[++cnt] = (edge){v, h[u], w}; h[u] = cnt;
}
double d_t[N]; int vis[N];
priority_queue<pdi, vector<pdi>, greater<pdi> > q;
void a_star(int s, int t) {
I::dij(t, s, d_t);
q.push(make_pair(d_t[s], s));
while(!q.empty()) {
int u = q.top().sec; double d = q.top().fir; q.pop();
if(u == t) if((en -= d) < 0) return;
vis[u]++;
for(int i=h[u];i;i=e[i].ne) {
int v = e[i].v;
q.push(make_pair(d - d_t[u] + d_t[v] + e[i].w, v));
}
}
}
int main() {
freopen("in", "r", stdin);
n=read(); m=read(); scanf("%lf", &en); s=1; t=n;
for(int i=1; i<=m; i++) u=read(), v=read(), scanf("%lf", &w), I::ins(v, u, w), ins(u, v, w);
a_star(s, t);
printf("%d\n", vis[t]);
}