【luogu P3393 逃离僵尸岛】 题解
题目链接:https://www.luogu.org/problemnew/show/P3393
被占领的点可以先连在一个点上然后只需要对这一个点bfs一遍就可以求所有的危险点
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int maxn = 2 * 1e5 + 10;
ll n, m, k, s, val[2], danger[maxn], ddis[maxn], dis[maxn], charge[maxn], v[maxn], u[maxn];
bool vis[maxn], vvis[maxn];
struct edge{
ll from, to, next, len;
}e[maxn<<2], ee[maxn<<2];
ll cnt, head[maxn], cntt, headd[maxn];
queue<ll> dq, 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 ad(ll u, ll v, ll w)
{
ee[++cntt].from = u;
ee[cntt].len = w;
ee[cntt].next = headd[u];
ee[cntt].to = v;
headd[u] = cntt;
}
void SPFA()
{
while(!q.empty())
{
ll now = q.front(); q.pop();
vis[now] = 0;
for(ll i = head[now]; i != -1; i = e[i].next)
{
if(dis[e[i].to] > dis[now] + e[i].len && danger[e[i].to] == 0)
{
dis[e[i].to] = dis[now] + e[i].len;
if(!vis[e[i].to])
{
q.push(e[i].to);
vis[e[i].to] = 1;
}
}
}
}
}
void BFS()
{
while(!dq.empty())
{
ll now = dq.front(); dq.pop();
vis[now] = 0;
for(ll i = headd[now]; i != -1; i = ee[i].next)
{
if(ddis[ee[i].to] > ddis[now] + ee[i].len)
{
ddis[ee[i].to] = ddis[now] + ee[i].len;
if(!vvis[ee[i].to])
{
dq.push(ee[i].to);
vvis[ee[i].to] = 1;
}
}
}
}
}
int main()
{
memset(head, -1, sizeof(head));
memset(headd, -1, sizeof(headd));
memset(dis, 127, sizeof(dis));
memset(ddis, 127, sizeof(ddis));
scanf("%lld%lld%lld%lld%lld%lld",&n,&m,&k,&s,&val[0],&val[1]);
for(ll i = 1; i <= k; i++)
{
ll u;
scanf("%lld",&u);
danger[u] = 1;
ad(u, 0, 1);
ad(0, u, 1);
}
for(ll i = 1; i <= m; i++)
{
scanf("%lld%lld",&u[i],&v[i]);
ad(u[i], v[i], 1);
ad(v[i], u[i], 1);
}
dq.push(0), ddis[0] = 0, vvis[0] = 1;
BFS();
for(ll i = 1; i <= n; i++)
if(ddis[i] <= s+1)
charge[i] = 1;
for(ll i = 1; i <= m; i++)
{
if(danger[u[i]] != 1 && danger[v[i]] != 1)
{
add(u[i], v[i], val[charge[v[i]]]);
add(v[i], u[i], val[charge[u[i]]]);
}
}
q.push(1), dis[1] = 0, vis[1] = 1;
SPFA();
/*for(ll i = 0; i <= n; i++)
cout<<charge[i]<<" ";*/
printf("%lld",dis[n]-val[charge[n]]);
return 0;
}
【luogu P3393 逃离僵尸岛】 题解的更多相关文章
- luogu P3393 逃离僵尸岛-搜索剪枝+spfa
P3393 逃离僵尸岛 题目描述 小a住的国家被僵尸侵略了!小a打算逃离到该国唯一的国际空港逃出这个国家. 该国有N个城市,城市之间有道路相连.一共有M条双向道路.保证没有自环和重边. K个城市已经被 ...
- luogu P3393 逃离僵尸岛
luoguP3393逃离_僵尸岛_ 一道洛谷不知道哪门子月赛的题 可以用此题来练习最短路算法 SPFA和dijkstra的练习题(关于Floyed,他死了 思路: 本题是最短路板子. 首先就是建立虚点 ...
- Luogu P3393 逃离僵尸岛【最短路】By cellur925
题目传送门 题目大意:(其实概括出来也就基本做完了hh)在一张有$n$个点,$m$条边的无向图上,有$k$个点是不能经过的,而与之距离不超过$s$的点,到他们会花费$Q$元,到其他点会花费$p$元,求 ...
- P3393 逃离僵尸岛
P3393 逃离僵尸岛 啊.好久不写dij手都生了 这道题就是预先处理出是否是危险城市,然后跑一个最短路就行了 然后因为我感觉这个对时间要求不大紧.判断危险城市时就写了个电风扇(DFS) 然后T飞了呜 ...
- [题解] 洛谷 P3393 逃离僵尸岛
题目TP门 很明显是一个最短路,但是如何建图才是关键. 对于每一个不可遍历到的点,可以向外扩散,找到危险城市. 若是对于每一个这样的城市进行搜索,时间复杂度就为\(O(n^2)\),显然过不了.不妨把 ...
- 洛谷⑨月月赛Round2 P3393逃离僵尸岛[最短路]
题目描述 小a住的国家被僵尸侵略了!小a打算逃离到该国唯一的国际空港逃出这个国家. 该国有N个城市,城市之间有道路相连.一共有M条双向道路.保证没有自环和重边. K个城市已经被僵尸控制了,如果贸然闯入 ...
- 洛谷P3393 逃离僵尸岛
题目描述 小a住的国家被僵尸侵略了!小a打算逃离到该国唯一的国际空港逃出这个国家. 该国有N个城市,城市之间有道路相连.一共有M条双向道路.保证没有自环和重边. K个城市已经被僵尸控制了,如果贸然闯入 ...
- luogu 3393 逃离僵尸岛
题目描述 小a住的国家被僵尸侵略了!小a打算逃离到该国唯一的国际空港逃出这个国家. 该国有N个城市,城市之间有道路相连.一共有M条双向道路.保证没有自环和重边. K个城市已经被僵尸控制了,如果贸然闯入 ...
- 洛谷P3393逃离僵尸岛 最短路
貌似一直不写题解不太好QAQ 但是找不到题啊... 随便写点水题来补博客吧 题目不pa了,点链接吧... 点我看题 很明显这是道sb题... 思路: 对于每一个僵尸城市预处理其 s 距离内的城市,然 ...
随机推荐
- 三个缓存数据库Redis、Memcache、MongoDB
>>Memcached Memcached的优点:Memcached可以利用多核优势,单实例吞吐量极高,可以达到几十万QPS(取决于key.value的字节大小以及服务器硬件性能,日常环境 ...
- MAC OS===>IntelliJ IDEA__ant__zookeeper源码编译
1:配置ant环境 https://archive.apache.org/dist/ant/binaries/ 官网下载文件 1.10.0以上需要JDK1.8以上 否则会报 Exception i ...
- HttpContext.Current.Request.RawUrl是什么意思?
原始 URL 定义为 URL 中域信息之后的部分.在 URL 字符串 http://www.contoso.com/articles/recent.aspx 中,原始 URL 为/articles/r ...
- for 循环的时候 append() 是移动不是复制
使用for 的时候,append() 不是复制,而是移动,只有最后一个元素才真正的append() 到了 解决办法: 1. 使用字符串: 2.使用clone();
- Codeforces(Round #93) 126 B. Password
B. Password time limit per test 2 seconds memory limit per test 256 megabytes Asterix, Obelix an ...
- 跳过图片反盗链js
页面增加<iframe> <iframe id="ifa" style="display:none" /> 原来html: <im ...
- git 回滚到上个版本命令以及忽略某些文件提交
1.git回滚到上个版本 git reset --hard FETCH_HEAD 2.git忽略某些文件的提交 以前是用默认的.gitignore 然后再里面默认某些文件不提交.但是有个问题,.git ...
- mongodb学习总结
安装mongodb: 1.下载服务器最新稳定版本(选择偶数号的版本号),mongodb的版本管理偶数号为稳定版,奇数号为开发版. 2.安装时默认安装在c盘,可以选择自定义选项来改变安装路径. 3.安装 ...
- urlx
2015-09-24 23:41:26 centos6.6下安装MongoDB3.0.1 https://www.percona.com/doc/percona-tokumx/installation ...
- 【Leetcode】【Medium】Permutations
Given a collection of numbers, return all possible permutations. For example,[1,2,3] have the follow ...