题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2680

题目意思:实质就是给定一个多源点到单一终点的最短路。

卑鄙题~~~有向图。初始化map时 千万不要写成 map[i][j] = map[j][i] = X。

 #include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
using namespace std; #define INF 0xfffffff
const int maxn = + ;
int dist[maxn], map[maxn][maxn], vis[maxn];
int n, m, s; void Init()
{
for (int i = ; i <= n; i++)
{
for (int j = ; j <= n; j++)
map[i][j] = (i == j ? : INF);
}
int p, q, t, w;
for (int i = ; i < m; i++)
{
scanf("%d%d%d", &p, &q, &t);
if (map[p][q] > t)
map[p][q] = t; // 写成map[p][q] = map[q][p] = t 会wa的!!!
}
scanf("%d", &w);
for (int i = ; i < w; i++)
{
scanf("%d", &p);
map[][p] = map[p][] = ;
}
for (int i = ; i <= n; i++)
dist[i] = map[][i];
} void Dijkstra()
{
int u, maxx;
memset(vis, , sizeof(vis));
for (int i = ; i <= n; i++)
{
maxx = INF;
for (int j = ; j <= n; j++)
{
if (!vis[j] && dist[j] < maxx)
maxx = dist[u=j];
}
vis[u] = ;
for (int j = ; j <= n; j++)
{
if (dist[j] > dist[u] + map[u][j])
dist[j] = dist[u] + map[u][j];
}
}
} int main()
{
while (scanf("%d%d%d", &n, &m, &s) != EOF)
{
Init();
Dijkstra();
printf("%d\n", dist[s] == INF ? - : dist[s]);
}
return ;
}

hdu 2680 Choose the best route 解题报告的更多相关文章

  1. hdu 2680 Choose the best route

    题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=2680 Choose the best route Description One day , Kiki ...

  2. hdu 2680 Choose the best route (dijkstra算法 最短路问题)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2680 Choose the best route Time Limit: 2000/1000 MS ( ...

  3. HDU 2680 Choose the best route 最短路问题

    题目描述:Kiki想去他的一个朋友家,他的朋友家包括所有的公交站点一共有n 个,一共有m条线路,线路都是单向的,然后Kiki可以在他附近的几个公交站乘车,求最短的路径长度是多少. 解题报告:这道题的特 ...

  4. hdu 2680 Choose the best route (dijkstra算法)

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=2680 /************************************************* ...

  5. HDU 2680 Choose the best route(SPFA)

    Problem DescriptionOne day , Kiki wants to visit one of her friends. As she is liable to carsickness ...

  6. HDU 2680 Choose the best route(多起点单终点最短路问题)题解

    题意:小A要乘车到s车站,他有w个起始车站可选,问最短时间. 思路:用Floyd超时,Dijkstra遍历,但是也超时.仔细看看你会发现这道题目好像是多源点单终点问题,终点已经确定,那么我们可以直接转 ...

  7. HDU 2068 Choose the best route

    http://acm.hdu.edu.cn/showproblem.php?pid=2680 Problem Description One day , Kiki wants to visit one ...

  8. hdu 1002.A + B Problem II 解题报告

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1002 题目意思:就是大整数加法. 两年几前做的,纯粹是整理下来的. #include <stdi ...

  9. hdoj 2680 choose the best route

    Problem Description One day , Kiki wants to visit one of her friends. As she is liable to carsicknes ...

随机推荐

  1. 【ZOJ4053】Couleur(主席树,set,启发式)

    题意: 有n个位置,每个位置上的数字是a[i],现在有强制在线的若干个单点删除操作,每次删除的位置都不同,要求每次删除之后求出最大的连续区间逆序对个数 n<=1e5,1<=a[i]< ...

  2. set_include_path() &&get_include_path()用法

    function initialize(){    set_include_path(get_include_path().PATH_SEPARATOR . "core/");   ...

  3. PHPstorm注册码(7.1.3)

    UserName EMBRACE ===== LICENSE BEGIN ===== 18710-12042010 00000EsehCiFamTQe"7jHcPB16QOyk S" ...

  4. linux的cpu性能评估

    linux的cpu性能评估 参考自:自学it网,http://www.zixue.it/. (1)利用vmstat命令监控系统CPU[test@localhost ~]$ vmstat 2 3 #每2 ...

  5. PC下ubuntu查找PC串口并加入用户组

    1. 查看ttyS0隶属的组:ls -l /dev/ttyS0  //发现隶属于dialout组 输出: crw-rw---- 1 root dialout 4, 64  9月  9 08:23 /d ...

  6. Codeforces 540 D Bad Luck Island

    Discription The Bad Luck Island is inhabited by three kinds of species: r rocks, s scissors andp pap ...

  7. iOS APP 的生命周期

    1.在手机桌面上点击APP图标 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDi ...

  8. 解决Linux系统没有/etc/sysconfig/iptables文件

    Linux系统中,防火墙默认是不开启的,一般也没有配置过任何防火墙的策略,所以不存在/etc/sysconfig/iptables文件. 一.常规解决方法: 1.在控制台使用iptables命令随便写 ...

  9. 【转载】高性能IO模型浅析

    服务器端编程经常需要构造高性能的IO模型,常见的IO模型有四种: (1)同步阻塞IO(Blocking IO):即传统的IO模型. (2)同步非阻塞IO(Non-blocking IO):默认创建的s ...

  10. Intel processor brand names-Xeon,Core,Pentium,Celeron----Celeron

    http://en.wikipedia.org/wiki/Celeron Celeron From Wikipedia, the free encyclopedia     Celeron Produ ...