【luogu P3946 ことりのおやつ】 题解
题目链接:https://www.luogu.org/problemnew/show/P3946
交好几遍是因为虽然能过一直有提醒..强迫症qwq
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int maxn = 5 * 1e6 + 10;
ll n, m, s, t, g, q;
ll dis[maxn], h[maxn], l[maxn];
bool vis[maxn];
struct edge{
ll from, to, next, len;
}e[maxn<<2];
ll head[maxn], cnt;
queue<int> Q;
void add(ll u, ll v, ll w)
{
e[++cnt].from = u;
e[cnt].len = w;
e[cnt].next = head[u];
e[cnt].to = v;
head[u] = cnt;
}
void SPFA()
{
while(!Q.empty())
{
ll now = Q.front(); Q.pop();
vis[now] = 0;
for(int i = head[now]; i != -1; i = e[i].next)
{
//cout<<e[i].from<<" "<<e[i].to<<endl;
if(e[i].to == t && dis[e[i].to] > dis[now] + e[i].len)
{
dis[e[i].to] = dis[now] + e[i].len;
if(!vis[e[i].to])
{
Q.push(e[i].to);
vis[e[i].to] = 1;
}
continue;
}
if(dis[e[i].to] > dis[now] + e[i].len && (dis[e[i].from] + e[i].len) * q + h[e[i].to] <= l[e[i].to])
{
dis[e[i].to] = dis[now] + e[i].len;
if(!vis[e[i].to])
{
Q.push(e[i].to);
vis[e[i].to] = 1;
}
}
}
}
}
int main()
{
memset(dis, 127, sizeof(dis));
memset(head, -1, sizeof(head));
scanf("%lld%lld%lld%lld%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 = 1; i <= m; i++)
{
ll u, v, w;
scanf("%lld%lld%lld",&u,&v,&w);
add(u, v, w);
add(v, u, w);
}
dis[s] = 0, vis[s] = 1, Q.push(s);
SPFA();
if(dis[t] <= g)
printf("%lld",dis[t]);
else
printf("wtnap wa kotori no oyatsu desu!\n");
return 0;
}
隐约雷鸣,阴霾天空,但盼风雨来,能留你在此。
隐约雷鸣,阴霾天空,即使天无雨,我亦留此地。