题目链接: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. 无记录时显示gridview表头,并增加一行显示“没有记录”【绑定SqlDataSource控件时】

    原文发布时间为:2008-08-04 -- 来源于本人的百度文章 [由搬家工具导入] using System;using System.Data;using System.Configuration ...

  2. web信息搜索之目标扫描篇

    https://blog.csdn.net/dongfei2033/article/details/78175421

  3. (7)ASP.NET WEB服务器控件

    1. <body> <form id="form1" runat="server"> <div> <asp:Label ...

  4. CSS 居中 可随着浏览器变大变小而居中

    关键代码: 外部DIV使用: text-align:center; 内部DIV使用: margin-left:auto;margin-right:auto 例: <div style=" ...

  5. iOS release版本去除NSLog打印信息

    因为NSLog的输出还是比较消耗系统资源的,而且输出的数据也可能会暴露出App里的保密数据,所以发布正式版时需要把这些输出全部屏蔽掉. 我们可以在发布版本前先把所有NSLog语句注释掉,等以后要调试时 ...

  6. Git checkout on a remote branch does not work

    I believe this occurs when you are trying to checkout a remote branch that your local git repo is no ...

  7. BUPT复试专题—统计字母(2008)

    题目描述 给定一个只有小写英文字母组成的字符串,串长为n.请你编写程序求出这个字符串中出现次数最多的字母. 输入 输入的第一行为t(0 < t < 10),表示有t组测试用例.对于每组测试 ...

  8. IOS UIPickView+sqlite 选择中国全部城市案例

    1.案例简单介绍 通过读取文件.将中国全部城市写入sqlite数据库中,现通过UIPickView实现中国全部城市的选择,效果图例如以下所看到的 2.城市对象模型 中国全部城市数据请看http://b ...

  9. RAC改动归档文件夹

    逐个节点改动 关闭全部节点,启动单节点(rac1)到mount状态 SQL> startup mount; 改动server參数配置 SQL> alter system set clust ...

  10. javascript 总结(持续更新)

    1.jQuery对象转DOM对象. jQuery对象转DOM对象有两种方法,[index]和get(index). var $cr = $("#cr"); //jQuery对象 v ...