最短路 || HDU 2066 一个人的旅行
本草的旅行故事(✺ω✺),可以从S个点中的任意一个开始,到达D个点中的任意一个,求最短路
*解法:把草儿的家记成点0,S个点与0的距离为0,然后spfa求最短路
又是改了一万次,①多组数据啊 ②改完多组数据记得加初始化啊 ③无向图反着也要建啊
脑子可能被我丢在被窝里了zzzzZ
#include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
using namespace std;
#define SZ 20005
#define INF 1e9+10
int head[SZ],nxt[SZ],tot = ;
struct edge
{
int t,d;
}l[SZ];
void build(int f,int t,int d)
{
l[++tot] = (edge){t,d};
nxt[tot] = head[f];
head[f] = tot;
}
queue<int> q;
bool use[SZ];
int dist[SZ];
void spfa(int s)
{
memset(dist, , sizeof(dist));
memset(use, , sizeof(use));
use[s] = ;
dist[s] = ;
q.push(s);
while(!q.empty())
{
int u = q.front(); q.pop();
use[u] = ;
for(int i = head[u];i;i = nxt[i])
{
int v = l[i].t;
if(dist[v] > dist[u] + l[i].d)
{
dist[v] = dist[u] + l[i].d;
if(!use[v])
use[v] = , q.push(v);
}
}
}
return;
}
int main()
{
int T, S, D;
while(scanf("%d %d %d", &T, &S, &D) != EOF)
{
memset(head, , sizeof(head));
tot = ;
for(int i = ; i < T; i++)
{
int x, y, z;
scanf("%d %d %d", &x, &y, &z);
build(x, y, z);
build(y, x, z);
}
for(int i = ;i < S; i++)
{
int x;
scanf("%d", &x);
build(, x, );
build(x, , );//反着也要建
}
spfa();
int minn = INF;
for(int i = ; i < D; i++)
{
int ed;
scanf("%d", &ed);
minn = min(minn, dist[ed]);
}
printf("%d\n", minn);
}
return ;
}
最短路 || HDU 2066 一个人的旅行的更多相关文章
- hdu 2066 一个人的旅行
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=2066 一个人的旅行 Description 虽然草儿是个路痴(就是在杭电待了一年多,居然还会在校园里迷 ...
- hdu - 2066 一个人的旅行(基础最短路)
http://acm.hdu.edu.cn/showproblem.php?pid=2066 把与草儿相连的城市最短距离置为0,然后进行dijkstra,在t个城市里找出距离最近的一个即可. #inc ...
- HDU 2066 一个人的旅行(单源最短路SPFA)
Description 虽然草儿是个路痴(就是在杭电待了一年多,居然还会在校园里迷路的人,汗~),但是草儿仍然很喜欢旅行,因为在旅途中 会遇见很多人(白马王子,^0^),很多事,还能丰富自己的阅历,还 ...
- hdu 2066 一个人的旅行 Dijkstra
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2066 题意分析:以草儿家为原点,给出城市间相互抵达的时间,给出草儿想去的城市,求最短时间.典型的单源最 ...
- hdu 2066 一个人的旅行(最短路问题)
最短路································· 类似的问题还有好多不会!慢慢学吧!!!!. 进步,哪怕每天一点也行! (恋爱不是小事,确实小事的积累!(听着酷狗音乐台说的,很 ...
- HDU 2066 一个人的旅行(dijkstra水题+判重边)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2066 题目大意:输入数据有多组,每组的第一行是三个整数T,S和D,表示有T条路,和草儿家相邻的城市的有 ...
- HDU——2066一个人的旅行(优先队列SPFA水题)
一个人的旅行 Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Sub ...
- hdu 2066 一个人的旅行 解题报告
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2066 题目意思:给出T条路,和草儿家相邻的城市编号,以及草儿想去的地方的编号.问从草儿家到达草儿想去的 ...
- HDU 2066 一个人的旅行 - from lanshui_Yang
Problem Description 虽然草儿是个路痴(就是在杭电待了一年多,居然还会在校园里迷路的人,汗~),但是草儿仍然很喜欢旅行,因为在旅途中 会遇见很多人(白马王子,^0^),很多事,还能丰 ...
随机推荐
- centos7命令行模式安装&&配置_br0+kvm+虚拟机+添加硬盘+快照及恢复
KVM创建虚拟机步骤 Submitted by zhaoley on October 18, 2016 - 10:43am 测试环境: 1: 43.243.130.89, CentOS Linux r ...
- Nginx: 统计PV、UV、独立IP
1.概念: UV(Unique Visitor):独立访客,将每个独立上网电脑(以cookie为依据)视为一位访客,一天之内(00:00-24:00),访问您网站的访客数量.一天之内相同cookie的 ...
- emacs编辑c文件时,大括号的跳转(转载)
转自:http://forum.ubuntu.org.cn/viewtopic.php?f=68&t=26701 `C-M-n' Move forward over a parenthetic ...
- Codeforces - 474D - Flowers - 构造 - 简单dp
https://codeforces.com/problemset/problem/474/D 这道题挺好的,思路是这样. 我们要找一个01串,其中0的段要被划分为若干个连续k的0. 我们设想一个长度 ...
- (水题)洛谷 - P1996 - 约瑟夫问题 - 链表
https://www.luogu.org/problemnew/show/P1996 试了一下数组实现的双向链表,是挺难用的,估计是应该写个get_next()函数比直接用next数组好. #inc ...
- Cg profiles,如何使用CGC编译Cg语言(转)
抄“GPU Programming And Cg Language Primer 1rd Edition” 中文名“GPU编程与CG语言之阳春白雪下里巴人” 计算机只能理解和执行由0.1序列(电压序列 ...
- 【Tip】JavaScript
『JavaScript』 『引用网络资源』 JQuery <script src="http://code.jquery.com/jquery-latest.js">& ...
- C#递归拷贝文件夹下文件以及文件夹
public bool CopyOldLabFilesToNewLab(string sourcePath, string savePath) { if (!Directory.Exists(save ...
- 继续(3n+1)猜想 (25)
#include <algorithm> #include <iostream> using namespace std; int main(){ ] = { }; ], nu ...
- hdu1233 还是畅通工程 基础最小生成树
//克鲁斯卡尔 #include<iostream> #include<algorithm> using namespace std; ; struct node { int ...