【】maze
【链接】点击打开链接
【题意】
【题解】
【错的次数】
【反思】
【代码】
#include <bits/stdc++.h>
using namespace std; const int N = 5e3, INF = 0x3f3f3f3f; int n, m, k, dis[N+10],f[N+10];
vector <pair<int,int> > G[N + 10];
queue <int> dl;
bool inq[N + 10]; int ff(int x) {
if (f[x] == x) return x;
else
return f[x] = ff(f[x]);
} int main() {
//freopen("F:\\rush.txt", "r", stdin);
ios::sync_with_stdio(0), cin.tie(0);
cin >> n >> m >> k;
for (int i = 1; i <= n; i++) f[i] = i;
for (int i = 1; i <= m; i++) {
int x, y, z;
cin >> x >> y >> z;
if (ff(x) != ff(y)) f[ff(x)] = ff(y);
G[x].push_back(make_pair(y, z)), G[y].push_back(make_pair(x, z));
}
if (ff(1) != ff(n)) return cout << "Oh no!" << endl, 0;
memset(dis, INF, sizeof dis);
dis[n] = 0, inq[n] = 1;
dl.push(n);
while (!dl.empty()) {
int x = dl.front(); dl.pop();
inq[x] = false;
for (auto temp : G[x]) {
if (dis[temp.first] > dis[x] + temp.second) {
dis[temp.first] = dis[x] + temp.second;
if (!inq[temp.first]) {
inq[temp.first] = true;
dl.push(temp.first);
}
}
}
}
int ans = dis[1];
for (int i = 1; i <= k; i++) {
int x;
cin >> x;
if (ff(x) == ff(1) && ff(x) == ff(n)) ans = min(ans, dis[x]);
}
cout << ans << endl;
return 0;
}
【】maze的更多相关文章
- 【南京邮电】maze 迷宫解法
[南京邮电]maze 迷宫解法 题目来源:南京邮电大学网络攻防训练平台. 题目下载地址:https://pan.baidu.com/s/1i5gLzIt (密码rijss) 0x0 初步分析 题目中给 ...
- 【&】位与运算符【|】位或运算符之权限控制算法
[&]位与运算符: 按位与运算符"&"是双目运算符. 其功能是参与运算的两数各对应的二进位相与.只有对应的两个二进位均为1时,结果位才为1 ,否则为0.参与运算的数 ...
- 存储过程 分页【NOT IN】和【>】效率大PK 千万级别数据测试结果
use TTgoif exists (select * from sysobjects where name='Tonge')drop table Tongecreate table Tonge( I ...
- 普通方式 分页【NOT IN】和【>】效率大PK 千万级别数据测试结果
首现创建一张表,然后插入1000+万条数据,接下来进行测试. use TTgoif exists (select * from sysobjects where name='Tonge')drop t ...
- java byte【】数组与文件读写(增加新功能)
今天在测试直接写的文章: java byte[]数组与文件读写 时,想调用FileHelper类对字节数组以追加的方式写文件,结果无论怎样竟然数据录入不全,重新看了下文件的追加模式,提供了两种方式: ...
- Spring 当 @PathVariable 遇上 【. # /】等特殊字符
@PathVariable注解应该不是新鲜东西了Spring3.0就开始有了 URL中通过加占位符把参数传向后台 举个栗子,如下比较要说的内容比较简单就大概齐的写一下 画面侧 $.ajax({ typ ...
- 【php正则】php正则匹配UTF-8格式的中文汉字 和 【,】【,】【。】等符号
1.php正则匹配UTF-8格式的中文汉字 和 [,][,][.]等符号 if (preg_match_all("/([\x{4e00}-\x{9fa5}]+((,)?)+((,)?)+(( ...
- 公式中表达单个双引号【"】和空值【""】的方法及说明
http://club.excelhome.net/thread-661904-1-1.html 有人问为什么不用三个双引号"""来表示单个双引号["]呢,如果 ...
- ubuntu fcitx google 输入法打不出中括号【】
编辑/usr/share/fcitx/data/punc.mb.zh_CN, 将 [ · ] 「 」 这部分改成自己习惯的: [ [ ] ] 保存后,重启一下fcitx就OK了.
随机推荐
- 排序(1)---------选择排序(C语言实现)
选择排序的基本思想: 选择排序(Selection sort)是一种简单直观的排序算法. 它的工作原理例如以下.首先在未排序序列中找到最小(大)元素,存放到排序序列的起始位置,然后,再从剩余未排序元素 ...
- hdoj-1593-find a way to escape【数学题】
find a way to escape Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others ...
- CDH版本大数据集群下搭建Avro(hadoop-2.6.0-cdh5.5.4.gz + avro-1.7.6-cdh5.5.4.tar.gz的搭建)
下载地址 http://archive.cloudera.com/cdh5/cdh/5/avro-1.7.6-cdh5.5.4.tar.gz
- 智能指针shared_ptr, auto_ptr, scoped_ptr, weak_ptr总结
看这里: http://blog.csdn.net/lollipop_jin/article/details/8499530 shared_ptr可以多线程同时读,但是涉及到写,需要加锁. share ...
- UnrealEngine4针对游戏模式的思考
游戏能够概括为三类:单进程联机(超级玛丽).小规模联机(魔兽争霸.CS),大规模联机(魔兽世界). watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvZmx1c ...
- 团队作业-Beta冲刺(3)
这个作业属于哪个课程 https://edu.cnblogs.com/campus/xnsy/SoftwareEngineeringClass2 这个作业要求在哪里 https://edu.cnblo ...
- 福建省第八届 Triangles
Problem Description This is a simple problem. Given two triangles A and B, you should determine they ...
- vue打包添加样式兼容前缀
在ios8 版本上的h5对flex的支持不太好,需要有兼容的写法. vue-cli自带了postCss autoprefixer 进行兼容处理,配置如下 在vue-loader.config.js中开 ...
- 【Codeforces Round #429 (Div. 2) A】Generous Kefa
[Link]:http://codeforces.com/contest/841/problem/A [Description] [Solution] 模拟,贪心,每个朋友尽量地多给气球. [Numb ...
- 杭电1102 Constructing Roads
Constructing Roads Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Other ...