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

这道题值得一提的两点:
在图论中注意重边问题是必须的,有向无向也是同等重要的,如这道题 from station p to station q说的就很清楚是有向图
此题如果暴力求解把每个临近的车站都作为源点走一遍,就会超时。此时的做法是
在与临近的车站加上一个0,并使其的距离为零,这样就可以转化成单源点的问题

#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
using namespace std;
const int maxint=;
int dist[maxint];
int c[maxint][maxint];
int s[maxint];
int qu;
int n,m;
void solve(int v){
for(int i=;i<=n;i++){
dist[i]=c[v][i];
s[i]=;
}
s[v]=;
dist[v]=;
for(int i=;i<=n;i++){
int min=;
int k;
for(int j=;j<=n;j++){
if(!s[j]&&dist[j]<min) { min=dist[j];
k=j; }
}
if(min==)
break;
s[k]=;
for(int j=;j<=n;j++)
{
if(s[j]==&&dist[j]>dist[k]+c[k][j])
dist[j]=dist[k]+c[k][j];
} }
}
int main(){
while(scanf("%d %d %d",&n,&m,&qu)!=EOF){
for(int i=;i<;i++){
for(int j=;j<;j++){
c[i][j]=;
}
}
int a,b,w;
for(int i=;i<=m;i++){
scanf("%d%d%d",&a,&b,&w);
if(w<c[a][b]){
c[a][b]=w;
}
}//无向图,并且去重
int e;
scanf("%d",&e);
int f;
for(int i=;i<e;i++){
scanf("%d",&f);
c[][f]=;
}
solve();
if(dist[qu]==)
printf("-1\n");
else
printf("%d\n",dist[qu]); } }

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. HDU2680 Choose the best route 最短路 分类: ACM 2015-03-18 23:30 37人阅读 评论(0) 收藏

    Choose the best route Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Ot ...

  3. Choose the best route(最短路)dijk

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

  4. HDU2680 Choose the best route 2017-04-12 18:47 28人阅读 评论(0) 收藏

    Choose the best route Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 32768/32768K (Java/Othe ...

  5. 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 ( ...

  6. hdu-2680 Choose the best route(最短路)

    题目链接: Choose the best route Time Limit: 2000/1000 MS (Java/Others)     Memory Limit: 32768/32768 K ( ...

  7. 最短路问题-- Dijkstra Choose the best route

    Choose the best route Problem Description One day , Kiki wants to visit one of her friends. As she i ...

  8. hdoj 2680 choose the best route

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

  9. HDU 2680 Choose the best route(SPFA)

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

  10. HDU 2068 Choose the best route

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

随机推荐

  1. cookie记录用户名和密码

    getAttribute和getParameter的区别: request.getAttribute():是request时设置的变量的值,用request.setAttribute("na ...

  2. Android图片异步加载之Android-Universal-Image-Loader

    将近一个月没有更新博客了,由于这段时间以来准备毕业论文等各种事务缠身,一直没有时间和精力沉下来继续学习和整理一些东西.最近刚刚恢复到正轨,正好这两天看了下Android上关于图片异步加载的开源项目,就 ...

  3. 【Android】数据存储-java IO流文件存储

    1.数据持久化:将在内存中的瞬时数据保存在存储设备中.瞬时数据:设备关机数据丢失.持久化技术提供一种机制可以让数据在瞬时状态和持久状态之间转换. 2.Android中简单的三种存储方式:文件存储.Sh ...

  4. RedHat7 SELinux

    SELinux(Security-Enhanced Linux) 是美国国家安全局(NSA)对于强制访问控制的实现,是 Linux历史上最杰出的新安全子系统.NSA是在Linux社区的帮助下开发了一种 ...

  5. django开发框架之jumpserver

    发现一个不错的开源堡垒机 jumpserver: https://github.com/ibuler/jumpserver 最开始看的是jumpserver2.0.0 版本,具体的实现方式是: 1. ...

  6. springmvc使用@ResponseBody返回json乱码解决方法

    1.springmvc 3.2以上的版本解决乱码的方法: 第一步:在配置中加入: <mvc:annotation-driven> <mvc:message-converters re ...

  7. Factory Method 工厂方法模式

    Factory method工厂方法模式是一种实现了“工厂”概念的面向对象设计模式.就像其他创建型模式一样,它也是处理在不指定对象具体类型的情况下创建对象的问题.工厂方法模式的实质是“定义一个创建对象 ...

  8. html 之前学习响应式的笔记

    响应式的设计,根据用户设备的不同,用户屏幕大小不同,提供不同的网页设计http://mediaqueri.es/PhoneGap 使用2,如何模拟手机设备chome 浏览器 在32以上设备检测用 de ...

  9. width:100% 和 max-width:100%; 有区别吗【转藏】

    这个博客是基于“Pelican+Markdown+定制的my-gum主题”的.定制的主题将博文正文页面的 右边栏去掉,这导致在Firefox等浏览器中,正文中大的图片会突破正文块的宽度,高度也得不到限 ...

  10. AngularJS code converage

    karma-coverage The easiest way is to keep karma-coverage as a devDependency in your package.json. Mo ...