逃离僵尸岛

思路:

  spfa;

代码:

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm> using namespace std; #define maxn 200005
#define maxque 1800056
#define INF 1e12
#define ll long long ll n,m,E[maxque],V[maxque],cnt,head[maxn],dis[maxn];
ll que[maxque],k,s,tag[maxn],Q,P,val[maxn]; bool if_[maxn]; inline void in(ll &now)
{
char Cget=getchar();now=;
while(Cget>''||Cget<'') Cget=getchar();
while(Cget>=''&&Cget<='')
{
now=now*+Cget-'';
Cget=getchar();
}
} inline void edge_add(ll u,ll v)
{
E[++cnt]=head[u],V[cnt]=v,head[u]=cnt;
E[++cnt]=head[v],V[cnt]=u,head[v]=cnt;
} void spfa1()
{
ll h=,tail=,pos,u,v;
memset(if_,,sizeof(if_));
for(int i=;i<=n;i++) tag[i]=INF;
for(ll i=;i<=k;i++) in(pos),que[tail++]=pos,tag[pos]=,if_[pos]=true;
for(ll i=;i<=m;i++) in(u),in(v),edge_add(u,v);
while(h<tail)
{
ll now=que[h++];if_[now]=false;
for(ll i=head[now];i;i=E[i])
{
if(tag[now]+<tag[V[i]])
{
tag[V[i]]=tag[now]+;
if(!if_[V[i]]) que[tail++]=V[i],if_[V[i]]=true;
}
}
}
for(ll i=;i<=n;i++)
{
dis[i]=INF;
if(!tag[i]) val[i]=INF;
else if(tag[i]<=s) val[i]=Q;
else val[i]=P;
}
val[]=,val[n]=;
} void spfa2()
{
ll h=,tail=;memset(if_,,sizeof(if_));
dis[]=,que[tail++]=,if_[]=true;
while(h<tail)
{
ll now=que[h++];if_[now]=false;
for(ll i=head[now];i;i=E[i])
{
if(dis[now]+val[V[i]]<dis[V[i]])
{
dis[V[i]]=dis[now]+val[V[i]];
if(!if_[V[i]]) que[tail++]=V[i],if_[V[i]]=true;
}
}
}
cout<<dis[n];
} int main()
{
in(n),in(m),in(k),in(s),in(P),in(Q),spfa1(),spfa2();
return ;
}

AC日记——逃离僵尸岛 洛谷 P3393的更多相关文章

  1. AC日记——[SDOI2015]星际战争 洛谷 P3324

    题目描述 3333年,在银河系的某星球上,X军团和Y军团正在激烈地作战. 在战斗的某一阶段,Y军团一共派遣了N个巨型机器人进攻X军团的阵地,其中第i个巨型机器人的装甲值为Ai.当一个巨型机器人的装甲值 ...

  2. AC日记——联合权值 洛谷 P1351

    题目描述 无向连通图G 有n 个点,n - 1 条边.点从1 到n 依次编号,编号为 i 的点的权值为W i ,每条边的长度均为1 .图上两点( u , v ) 的距离定义为u 点到v 点的最短距离. ...

  3. AC日记——I Hate It 洛谷 P1531

    题目背景 很多学校流行一种比较的习惯.老师们很喜欢询问,从某某到某某当中,分数最高的是多少.这让很多学生很反感. 题目描述 不管你喜不喜欢,现在需要你做的是,就是按照老师的要求,写一个程序,模拟老师的 ...

  4. AC日记——神奇的幻方 洛谷 P2615(大模拟)

    题目描述 幻方是一种很神奇的N*N矩阵:它由数字1,2,3,……,N*N构成,且每行.每列及两条对角线上的数字之和都相同. 当N为奇数时,我们可以通过以下方法构建一个幻方: 首先将1写在第一行的中间. ...

  5. AC日记——[CQOI2009]DANCE跳舞 洛谷 P3153

    [CQOI2009]DANCE跳舞 思路: 二分+最大流: 代码: #include <cstdio> #include <cstring> #include <iost ...

  6. AC日记——松江1843路 洛谷七月月赛

    松江1843路 思路: 三分: 代码: #include <bits/stdc++.h> using namespace std; #define maxn 100005 #define ...

  7. AC日记——严酷的训练 洛谷 P2430

    严酷的训练 思路: 背包: 代码: #include <bits/stdc++.h> using namespace std; #define maxn 5005 int n,m,bi[m ...

  8. AC日记——[SDOI2010]大陆争霸 洛谷 P3690

    [SDOI2010]大陆争霸 思路: dijkstra模板: 代码: #include <bits/stdc++.h> using namespace std; #define maxn ...

  9. AC日记——小魔女帕琪 洛谷 P3802

    小魔女帕琪 思路: 概率公式计算: 代码: #include <bits/stdc++.h> using namespace std; ],sig; int main() { ;i< ...

随机推荐

  1. DataGridView使用

    DataGridView控件概述 DataGridView 控件代码目录(Windows 窗体) 未绑定数据列 定义:可能想要显示并非来自数据源的一列数据,这种列称为未绑定列. 数据格式示例 如何:设 ...

  2. QThread中的互斥、读写锁、信号量、条件变量

    该文出自:http://www.civilnet.cn/bbs/browse.php?topicno=78431 在gemfield的<从pthread到QThread>一文中我们了解了线 ...

  3. 如何在MyEclipse下查看JDK源代码

    在MyEclipse中查看JDK类库的源代码~ 设置: 1.点 "window"-> "Preferences" -> "Java&quo ...

  4. Chrome Extension & Dark Theme

    Chrome Extension & Dark Theme https://chrome.google.com/webstore/detail/eimadpbcbfnmbkopoojfekhn ...

  5. [Java文件操作] 将素数输出到文件

    [要求]编写程序求出10万以内的所有素数,并将这些素数输出到一个文本文件中,每行文本只包含一个素数数据. import java.util.*; import java.io.*; public cl ...

  6. javasisst & JAVA8

    今天在服务器上启动tomcat7的时候,提示如下异常: java.io.IOException: invalid constant type: 15 具体看是javasisst抛出来的. 系统运行环境 ...

  7. 【Python】PYTHON九九乘法表

    python2.7 for i in range(1,10):  for j in range(1,i+1):    print j,'x',i,'=',j*i,'\t',  print '\n'pr ...

  8. LeetCode--Factorial Trailing Zeroes(注意)

    Given an integer n, return the number of trailing zeroes in n!. 问题描述:给出一个正整数n,计算n!结构后面有几个0.要求:在多项式时间 ...

  9. POJ 3415 后缀数组+单调栈

    题目大意: 给定A,B两种字符串,问他们当中的长度大于k的公共子串的个数有多少个 这道题目本身理解不难,将两个字符串合并后求出它的后缀数组 然后利用后缀数组求解答案 这里一开始看题解说要用栈的思想,觉 ...

  10. Codeforces Round #351 (VK Cup 2016 Round 3, Div. 2 Edition) A

    A. Bear and Game time limit per test 2 seconds memory limit per test 256 megabytes input standard in ...