http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2493

 #include <stdio.h>
#include <string.h>
#include <queue>
using namespace std;
const int maxn=;
const int maxm=maxn*maxn;
const long long INF=1LL<<;
int vis[maxn],head[maxn];
int n,m,cnt = ;
struct node
{
int u,v;
long long w;
int next; } edge[maxm]; inline void add(int u,int v,long long w)
{
edge[cnt].u = u;
edge[cnt].v = v;
edge[cnt].w = w;
edge[cnt].next = head[u];
head[u] = cnt++;
} void spfa(int s, long long dis[])
{ queue<int>q;
q.push(s);
vis[s] = ;
dis[s] = ;
while(!q.empty())
{
int u = q.front();
q.pop();
vis[u] = ;
for (int j = head[u]; j!=-; j= edge[j].next)
{
int v = edge[j].v;
long long w = edge[j].w;
if (dis[u]+w < dis[v])
{
dis[v] = dis[u]+w;
q.push(v);
vis[v] = ;
}
}
} }
void init()
{ }
int main()
{
int u,v;
long long w;
long long dis1[maxn],dis2[maxn];
while(~scanf("%d %d",&n,&m))
{
for (int i = ; i <= n; i++)
{
vis[i] = ;
dis1[i] = INF;
dis2[i] = INF;
head[i] = -;
}
cnt = ;
for (int i = ; i < m; i++)
{
scanf("%d %d %lld",&u,&v,&w);
add(u,v,w);
add(v,u,w);
}
int s,e;
long long min=INF;
scanf("%d %d",&s,&e);
spfa(s,dis1);//求出起点到所有点的最短路径
spfa(e,dis2);//求出终点到所有点的最短路径
for (int i = ; i < cnt; i++)//遍历所有的边
{
u = edge[i].u;
v = edge[i].v;
w = edge[i].w;
if (dis1[u]+dis2[v]+w/ < min)//S->u+e->v+w/2即为改变后的权值,找出最小的
min = dis1[u]+dis2[v]+w/;
}
if(min==INF)
{
puts("No solution");
continue;
}
printf("%lld\n",min);
}
return ;
}

Constructing Roads(spfa)的更多相关文章

  1. Constructing Roads——F

    F. Constructing Roads There are N villages, which are numbered from 1 to N, and you should build som ...

  2. Constructing Roads In JGShining's Kingdom(HDU1025)(LCS序列的变行)

    Constructing Roads In JGShining's Kingdom  HDU1025 题目主要理解要用LCS进行求解! 并且一般的求法会超时!!要用二分!!! 最后蛋疼的是输出格式的注 ...

  3. [ACM] hdu 1025 Constructing Roads In JGShining's Kingdom (最长递增子序列,lower_bound使用)

    Constructing Roads In JGShining's Kingdom Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65 ...

  4. HDU 1102 Constructing Roads

    Constructing Roads Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Other ...

  5. Constructing Roads (MST)

    Constructing Roads Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u ...

  6. HDU 1025 Constructing Roads In JGShining's Kingdom(二维LIS)

    Constructing Roads In JGShining's Kingdom Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65 ...

  7. hdu--(1025)Constructing Roads In JGShining's Kingdom(dp/LIS+二分)

    Constructing Roads In JGShining's Kingdom Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65 ...

  8. POJ 2421 Constructing Roads (最小生成树)

    Constructing Roads Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u ...

  9. hdu 1102 Constructing Roads Kruscal

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1102 题意:这道题实际上和hdu 1242 Rescue 非常相似,改变了输入方式之后, 本题实际上更 ...

随机推荐

  1. 体验SqlServer Express 2014

    想使用SQLServer Express记录一些数据,但使用起来并不令人愉快.SQLServer Express是一个免费的可用数据库,但似乎设置了一些门槛,多少显得并不真心实意.抛开版本(技术)限制 ...

  2. 抓包工具Fiddler及Charles

    一.抓包工具介绍 1.charles抓包如何抓取手机端数据包(安卓手机) (1)获取pc的IP地址 (2)打开charles里的[Proxy]-[Proxy setting],设置端口号,默认为888 ...

  3. centos添加永久的环境变量

    cd /etc/profile.d/ 创建一个sh文件 vi dotnetpath.sh 内容如下: export PATH=$PATH:/opt/dotnet 保存,重启,这就有了一个永久的环境变量

  4. Windows如何正确的修改administrator用户名

    无论是服务器还是电脑.修改默认的administrator的用户总是好的.话不多少.直接上图 1.win+r  输入:gpedit.msc 2.按照我下图的圈圈找到重命名系统管理员账户并自定义 3.重 ...

  5. S3C2440中断

    韦东山老师一期中断课程学习: 总结: 程序启动后工作流程,程序从0地址开始执行Reset  --> 重定位  -->ldr pc,=main [绝对跳转到SDRAM中执行main()函数] ...

  6. swift--Xcode7 使用Alamofire框架发送HTTP请求报错

    控制台打印的错误信息: Application Transport Security has blocked a cleartext HTTP (http://) resource load sinc ...

  7. Python之类方法,lambda,闭包简谈

    类方法,lambda,闭包 类方法 lambda 闭包 类方法 classmethod staticmethod instancemethod 类方法 类方法,通过装饰器@classmethod来标明 ...

  8. 解析 XML 数据

    在几个月前我有做过这样的记录,其目的是避免解析 XML 时手工编写太多的代码,造成重复的体力劳动.后来经过一番资料的查找,我发现其实并没有必要做这样的工具,因为 C# 已经为我们提供了更好的解决方案了 ...

  9. .Net操作Excel —— NPOI

    近期的两个项目都有关于NPOI的功能,经过了一点学习,自己也摸索了一会,感觉还有点意思.现在将部分代码分享一下.一部分是C#代码,一部分是VB.Net的,懒得修改了,基本上都是从项目文件中copy出来 ...

  10. C# WPF 无窗体传递消息

    WPF如果存在窗体(或至少,在任务栏有图标显示),互相传递消息是很容易的. 寻找目标窗体句柄->WindowsAPI SendMessage/PostMessage->目标窗体AddHoo ...