题目连接

http://acm.hdu.edu.cn/showproblem.php?pid=2066

一个人的旅行

Description

虽然草儿是个路痴(就是在杭电待了一年多,居然还会在校园里迷路的人,汗~),但是草儿仍然很喜欢旅行,因为在旅途中 会遇见很多人(白马王子,^0^),很多事,还能丰富自己的阅历,还可以看美丽的风景……草儿想去很多地方,她想要去东京铁塔看夜景,去威尼斯看电影,去阳明山上看海芋,去纽约纯粹看雪景,去巴黎喝咖啡写信,去北京探望孟姜女……眼看寒假就快到了,这么一大段时间,可不能浪费啊,一定要给自己好好的放个假,可是也不能荒废了训练啊,所以草儿决定在要在最短的时间去一个自己想去的地方!因为草儿的家在一个小镇上,没有火车经过,所以她只能去邻近的城市坐火车(好可怜啊~)。

Input

输入数据有多组,每组的第一行是三个整数$T,S$和$D$,表示有$T$条路,和草儿家相邻的城市的有$S$个,草儿想去的地方有$D$个;
接着有$T$行,每行有三个整数$a,b,time$,表示$a,\ b$城市之间的车程是$time$4小时;$(1 \leq (a,b) \leq 1000;a,b$ 之间可能有多条路)
接着的第$T+1$行有$S$个数,表示和草儿家相连的城市;
接着的第$T+2$行有$D$个数,表示草儿想去地方。

Output

输出草儿能去某个喜欢的城市的最短时间。

Sample Input

6 2 3
1 3 5
1 4 7
2 8 12
3 8 4
4 9 12
9 10 2
1 2
8 9 10

Sample Output

9

最短路。。

 #include<algorithm>
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<cstdio>
#include<vector>
#include<queue>
#include<map>
using std::min;
using std::cin;
using std::cout;
using std::endl;
using std::find;
using std::sort;
using std::pair;
using std::vector;
using std::multimap;
using std::priority_queue;
#define pb(e) push_back(e)
#define sz(c) (int)(c).size()
#define mp(a, b) make_pair(a, b)
#define all(c) (c).begin(), (c).end()
#define iter(c) decltype((c).begin())
#define cls(arr,val) memset(arr,val,sizeof(arr))
#define cpresent(c, e) (find(all(c), (e)) != (c).end())
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define tr(c, i) for (iter(c) i = (c).begin(); i != (c).end(); ++i)
const int N = ;
typedef unsigned long long ull;
struct P {
int w, v;
P(int i = , int j = ) :w(i), v(j) {}
inline bool operator<(const P &a) const {
return w > a.w;
}
};
struct Node { int to, w, next; };
struct Dijkstra {
Node G[N];
int tot, head[N], dist[N];
inline void init() {
tot = , cls(head, -);
}
inline void add_edge(int u, int v, int w) {
G[tot] = { v, w, head[u] }; head[u] = tot++;
}
inline void built(int n) {
int u, v, w;
rep(i, n) {
scanf("%d %d %d", &u, &v, &w);
add_edge(u, v, w), add_edge(v, u, w);
}
}
inline void dijkstra(vector<int> &st) {
cls(dist, 0x3f);
priority_queue<P> q;
rep(i, sz(st)) {
q.push(P(, st[i]));
dist[st[i]] = ;
}
while (!q.empty()) {
P t = q.top(); q.pop();
int u = t.v;
if (dist[u] < t.w) continue;
for (int i = head[u]; ~i; i = G[i].next) {
int &w = dist[G[i].to];
if (w > dist[u] + G[i].w) {
w = dist[u] + G[i].w;
q.push(P(w, G[i].to));
}
}
}
}
inline void work(int s, int d) {
int v, ans = 0x3f3f3f3f;
vector<int> A, B;
while (s--) { scanf("%d", &v); A.push_back(v); }
while (d--) { scanf("%d", &v); B.push_back(v); }
dijkstra(A);
rep(i, sz(B)) ans = min(ans, dist[B[i]]);
printf("%d\n", ans);
}
}go;
int main() {
#ifdef LOCAL
freopen("in.txt", "r", stdin);
freopen("out.txt", "w+", stdout);
#endif
int n, s, d;
while (~scanf("%d %d %d", &n, &s, &d)) {
go.init();
go.built(n);
go.work(s, d);
}
return ;
}

hdu 2066 一个人的旅行的更多相关文章

  1. hdu 2066 一个人的旅行 Dijkstra

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2066 题意分析:以草儿家为原点,给出城市间相互抵达的时间,给出草儿想去的城市,求最短时间.典型的单源最 ...

  2. hdu 2066 一个人的旅行(最短路问题)

    最短路································· 类似的问题还有好多不会!慢慢学吧!!!!. 进步,哪怕每天一点也行! (恋爱不是小事,确实小事的积累!(听着酷狗音乐台说的,很 ...

  3. HDU 2066 一个人的旅行(dijkstra水题+判重边)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2066 题目大意:输入数据有多组,每组的第一行是三个整数T,S和D,表示有T条路,和草儿家相邻的城市的有 ...

  4. hdu 2066 一个人的旅行 解题报告

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2066 题目意思:给出T条路,和草儿家相邻的城市编号,以及草儿想去的地方的编号.问从草儿家到达草儿想去的 ...

  5. hdu - 2066 一个人的旅行(基础最短路)

    http://acm.hdu.edu.cn/showproblem.php?pid=2066 把与草儿相连的城市最短距离置为0,然后进行dijkstra,在t个城市里找出距离最近的一个即可. #inc ...

  6. HDU 2066 一个人的旅行(单源最短路SPFA)

    Description 虽然草儿是个路痴(就是在杭电待了一年多,居然还会在校园里迷路的人,汗~),但是草儿仍然很喜欢旅行,因为在旅途中 会遇见很多人(白马王子,^0^),很多事,还能丰富自己的阅历,还 ...

  7. HDU 2066 一个人的旅行 - from lanshui_Yang

    Problem Description 虽然草儿是个路痴(就是在杭电待了一年多,居然还会在校园里迷路的人,汗~),但是草儿仍然很喜欢旅行,因为在旅途中 会遇见很多人(白马王子,^0^),很多事,还能丰 ...

  8. hdu 2066 一个人的旅行 最短路径

    一个人的旅行 Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Sub ...

  9. HDU 2066 一个人的旅行 (Dijkstra算法)

    一个人的旅行 Time Limit : 1000/1000ms (Java/Other)   Memory Limit : 32768/32768K (Java/Other) Total Submis ...

随机推荐

  1. 【LeetCode】13. Roman to Integer 罗马数字转整数

    题目: Given a roman numeral, convert it to an integer. Input is guaranteed to be within the range from ...

  2. 简单几步优化技巧令你的Windows7系统加速

    就算有再高的硬件配置,系统用久了还是会变慢,xp如此,win7同样是如此.其实系统用的如何完全在于个人使用习惯,只要掌握了以下三种方法,就可以让你的win7运行速度大大提升. 1.修改启动项程序 在你 ...

  3. 在 MVC 控制器中使用 构造函数时行依赖注入 (IoC)

    在 Controller 中使用 构造函数进行依赖注入 (IoC) 1. Controller 代码: ICard card; ICardCategory cardCategory; public C ...

  4. J2SE宏观总结

  5. Android内存泄漏分析

    周末去上海参加了安卓巴士组织的技术论坛,去了才发现自己基础很渣..... 其中提到了android的内存泄漏的问题,回来马上度娘(虽说度娘很渣),整理如下: 一.单例造成的内存泄漏 因为单例的静态特性 ...

  6. 使用.NET MVC框架项目开发流程(项目开发流程)

    MVC项目开发流程 整理需求,进行需求分析.项目设计. 整理数据项,建数据库做前期准备,并整理字典. 建立所需数据库表和视图和模型. 页面实现其初步功能(跳过逻辑后台代码),只是实现页面之间的跳转以及 ...

  7. 智能指针(三):unique_ptr使用简介

    我们知道auto_ptr通过复制构造或者通过=赋值后,原来的auto_ptr对象就报废了.所有权转移到新的对象中去了.而通过shared_ptr可以让多个智能指针对象同时拥有某一块内存的访问权.但假如 ...

  8. ng-class ionic

    我发现 ng-class="{yourclass:true,outerclass:false}" 竟然不起作用...囧.... 幸好有Google  .... <p ng-c ...

  9. 如何解决SWAT模型数据移动目录后出现的“SWAT2005.mdb database specified in your MasterProgress table does not exists. Please correct and try again”的问题

    方法: 1.用MS Access软件打开SWAT模型工程文件的数据文件,如“**流域模拟.mdb”,该文件一般存放在工程文件“**流域模拟.mxd”相同的路径: 2.打开以后,找到“MasterPro ...

  10. asp.net常用字符串函数

    /// <summary> /// 提取字符串中的数字 /// </summary> /// <param name="str"></pa ...