[洛谷P3946] ことりのおやつ(小鸟的点心)

题目大意:最短路,第$i$个点原有积雪$h_i$,极限雪高$l_i$(即雪超过极限雪高就不可以行走),每秒降雪$q$,ことり速度为$1m/s$,若时间大于$g$,则输出$wtnap wa kotori no oyatsu desu!$

题解:变形的最短路

卡点:1.终点不受极限雪高限制

C++ Code:

#include <cstdio>
#include <cstring>
using namespace std;
int n, m, S, T;
int q[1000010], h, t;
long long H[100010], l[100010], g, Q;
long long d[100010];
int head[100010], cnt;
bool vis[100010];
struct Edge {
	int to, nxt;
	long long w;
}e[1000010 << 1];
void add(int a, int b, long long c) {
	e[++cnt] = (Edge) {b, head[a], c}; head[a] = cnt;
}
void SPFA(int st) {
	memset(d, 0x3f, sizeof d);
	d[q[h = t = 0] = st] = 0;
	while (h <= t) {
		int u = q[h++];
		vis[u] = false;
		for (int i = head[u]; i; i = e[i].nxt) {
			int v = e[i].to; long long w = d[u] + e[i].w;
			if ((w * Q + H[v] > l[v]) && (v != T)) continue;
			if (d[v] > w) {
				d[v] = w;
				if (!vis[v]) {
					vis[v] = true;
					q[++t] = v;
				}
			}
		}
	}
//	printf("%lld
", d[T]);
	if (d[T] > g) puts("wtnap wa kotori no oyatsu desu!");
		else printf("%lld
", d[T]);
	return ;
	puts("ことりのおやつにしてやるぞー!");
}
int main() {
	scanf("%d%d%d%d%lld%lld", &n, &m, &S, &T, &g, &Q);
	for (int i = 1; i <= n; i++) scanf("%lld%lld", &H[i], &l[i]);
	for (int i = 0; i < m; i++) {
		int a, b; long long c;
		scanf("%d%d%lld", &a, &b, &c);
		add(a, b, c);
		add(b, a, c);
	}
	SPFA(S);
	return 0;
} 

  

原文地址:https://www.cnblogs.com/Memory-of-winter/p/9335167.html