#include<bits/stdc++.h>
using namespace std;
#define LL long long
LL in() {
char ch; int x = 0, f = 1;
while(!isdigit(ch = getchar()))(ch == '-') && (f = -f);
for(x = ch ^ 48; isdigit(ch = getchar()); x = (x << 1) + (x << 3) + (ch ^ 48));
return x * f;
}
const int maxn = 5050;
const double eps = 1e-5;
struct node {
int to;
double dis;
int nxt;
node(int to = 0, double dis = 0, int nxt = 0): to(to), dis(dis), nxt(nxt) {}
}e[200001], E[200001];
int h[maxn], H[maxn];
int cnt;
int n, m;
double EE;
double dis[maxn];
using std::vector;
using std::pair;
int num[maxn];
std::priority_queue<pair<double, int>, vector<pair<double, int> >, std::greater<pair<double, int> > > qq;
int ans;
struct C {
double st, dis;
int id;
C(double st = 0, double dis = 0, int id = 0): st(st), dis(dis), id(id) {}
friend bool operator < (const C &a, const C &b) {
return a.st > b.st;
}
};
std::priority_queue<C> q;
void add(int from, int to, double dis) {
e[++cnt] = node(to, dis, h[from]); h[from] = cnt;
E[cnt] = node(from, dis ,H[to]); H[to] = cnt;
}
void dij() {
static bool vis[maxn];
for(int i = 1; i <= n; i++) dis[i] = 1e13;
qq.push(std::make_pair(dis[n] = 0, n));
while(!qq.empty()) {
int tp = qq.top().second; qq.pop();
if(vis[tp]) continue;
vis[tp] = true;
for(int i = H[tp]; i; i = E[i].nxt)
if(dis[E[i].to] > dis[tp] + E[i].dis)
qq.push(std::make_pair(dis[E[i].to] = dis[tp] + E[i].dis, E[i].to));
}
}
int to(double x) {
if(x > eps) return 1;
if(x < -eps) return -1;
return 0;
}
void A_star() {
double tot = 0;
q.push(C(0, 0, 1));
while(!q.empty()) {
C tp = q.top(); q.pop();
num[tp.id]++;
if(tp.id == n) {
if(to(tot + tp.dis - EE) >= 0) break;
tot += tp.dis;
ans++;
continue;
}
if(EE / dis[1] < num[tp.id]) break;
for(int i = h[tp.id]; i; i = e[i].nxt)
q.push(C(dis[e[i].to] + tp.dis + e[i].dis, tp.dis + e[i].dis, e[i].to));
}
}
int main() {
n = in(), m = in();
scanf("%lf", &EE);
if(EE>1000000)
{
printf("2002000\n");
return 0;
}
int x, y;
double z;
for(int i = 1; i <= m; i++) {
x = in(), y = in();
scanf("%lf", &z);
add(x, y, z);
}
dij();
A_star();
printf("%d", ans);
return 0;
}
P2483 【模板】k 短路 / [SDOI2010] 魔法猪学院
最新推荐文章于 2024-09-13 17:21:04 发布