Constructing Roads(spfa)
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)的更多相关文章
- Constructing Roads——F
F. Constructing Roads There are N villages, which are numbered from 1 to N, and you should build som ...
- Constructing Roads In JGShining's Kingdom(HDU1025)(LCS序列的变行)
Constructing Roads In JGShining's Kingdom HDU1025 题目主要理解要用LCS进行求解! 并且一般的求法会超时!!要用二分!!! 最后蛋疼的是输出格式的注 ...
- [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 ...
- HDU 1102 Constructing Roads
Constructing Roads Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Other ...
- Constructing Roads (MST)
Constructing Roads Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u ...
- 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 ...
- 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 ...
- POJ 2421 Constructing Roads (最小生成树)
Constructing Roads Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u ...
- hdu 1102 Constructing Roads Kruscal
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1102 题意:这道题实际上和hdu 1242 Rescue 非常相似,改变了输入方式之后, 本题实际上更 ...
随机推荐
- CSS3设计炫目字体
阴影 .text-shadow{ text-shadow:#FF0000 0 0 10px; color:white; font-size:60px } 描边 <style> .text- ...
- 几种fullpage用法及demo
jQuery全屏滚动插件fullPage.js https://github.com/alvarotrigo/fullPage.js http://www.dowebok.com/77.html 全屏 ...
- Win10电脑如何更改开机启动项
https://jingyan.baidu.com/article/5970355284f0458fc1074049.html
- CAD在网页中增加一个射线
主要用到函数说明: IMxDrawBlockTableRecord::AddRay 向记录中增加一个射线,详细说明如下: 参数 说明 point1 射线上的点1 point2 射线上的点2 js代码实 ...
- BZOJ 4561: [JLoi2016]圆的异或并 扫描线 + set
看题解看了半天...... Code: #include<bits/stdc++.h> #define maxn 200010 #define ll long long using nam ...
- loader__demo_css
环境 node + yarn + webpack4.0 + webpack-cli + style-loader css-loader 文件结构 │ package.json │ webpack.co ...
- 兼容ie6的mvvm框架--san
最近,由于公司项目需要,使用百度mvvm框架san开发了一个兼容ie6的小项目.san的优势是强大的兼容性,能兼容到ie6.当初我自己好奇,尝试用san做了一个小型项目,这里记录一下.如果你也想尝试一 ...
- 推荐系统相关比赛-kaggle
from: 七月在线 电商推荐与销量预测相关案例 一.预测用户对哪个事件感兴趣(感兴趣不一定去参加) 用户历史参加事件.社交信息.浏览信息(app).要预测的事件 recall:召回率 准确率: 协同 ...
- SOUI界面库 添加 windows系统文件图标皮肤
最近在学习soui界面库.其中有用到SListCtrl这个控件来现在文件信息.控件用法基本上和mfc 的CListCtrl差不多.也支持图标显示.但是图标是要自己加入图标图片的.这个就有点不好弄.于是 ...
- vue组件 $children,$refs,$parent的使用详解
1)$refs 首先你的给子组件做标记.demo :<firstchild ref="one"></firstchild> 然后在父组件中,通过this.$ ...