CSUOJ 1808 地铁
Description
Bobo 居住在大城市 ICPCCamp。
Input
Output
Sample Input
3 3
1 2 1 1
2 3 2 1
1 3 1 1
3 3
1 2 1 1
2 3 2 1
1 3 1 10
3 2
1 2 1 1
2 3 1 1
Sample Output
1
3
2
Hint
#include<stdio.h>
#include<string.h>
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;
#define MAXN 100010
#define INF 0x3fffffff
typedef long long ll;
struct edge{
ll from, to, ci,w;
};
struct node{
ll x, sum;
int fa;//记录连接了几个点
friend bool operator <(node n1, node n2)
{
return n1.sum>n2.sum;
}
};
ll ans, n, m;
vector<int>G[MAXN];
vector<edge>edges;
priority_queue<node>q;
int vis[MAXN * 2];
void addedge(ll x, ll y, ll ci, ll w)
{
edge v = { x, y, ci, w };
edges.push_back(v);//边
G[x].push_back(edges.size() - 1);//点
}
void bfs()
{
node a = { 1, 0, -1 };
q.push(a);
while (!q.empty())
{
a = q.top();
q.pop();
if (a.x == n)
{
ans = a.sum;
return;
}
if (a.fa != -1 && vis[a.fa])
continue;
vis[a.fa] = 1;
for (int i = 0; i < G[a.x].size(); i++)
{
node b = a;
edge v = edges[G[a.x][i]];
b.x = v.to;
b.fa = G[a.x][i];
b.sum += v.w;
if (a.fa >= 0)
{
b.sum += abs(edges[a.fa].ci - v.ci);
}
q.push(b);
}
}
}
int main()
{
while (~scanf("%lld%lld", &n, &m))
{
for (int i = 0; i <= n; i++)
G[i].clear();
edges.clear();
for (int i = 1; i <= m; i++)
{
ll x, y, ci, w;
scanf("%lld%lld%lld%lld", &x, &y, &ci, &w);
addedge(x, y, ci, w);
addedge(y, x, ci, w);
}
ans = INF;
memset(vis, 0, sizeof(vis));
while (!q.empty())
q.pop();
bfs();
cout << ans<< endl;
}
return 0;
}
/**********************************************************************
Problem: 1808
User: leo6033
Language: C++
Result: AC
Time:1844 ms
Memory:19208 kb
**********************************************************************/
CSUOJ 1808 地铁的更多相关文章
- CSU 1808: 地铁 最短路
题目链接: http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1808 1808: 地铁 Time Limit: 5 SecMemory Limit: ...
- CSU 1808 - 地铁 - [最短路变形]
题目链接:http://acm.csu.edu.cn/csuoj/problemset/problem?pid=1808 Time limit: 5000 ms Memory limit: 13107 ...
- CSU 1808 地铁(最短路变形)
http://acm.csu.edu.cn/csuoj/problemset/problem?pid=1808 题意: Bobo 居住在大城市 ICPCCamp. ICPCCamp 有 n 个地铁站, ...
- 【最短路】【STL】CSU 1808 地铁 (2016湖南省第十二届大学生计算机程序设计竞赛)
题目链接: http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1808 题目大意: N个点M条无向边(N,M<=105),每条边属于某一条地铁Ci ...
- CSU 1808 地铁
题意: ICPCCamp 有 n 个地铁站,用 1,2,-,n 编号. m 段双向的地铁线路连接 n 个地铁站,其中第 i 段地铁属于 ci 号线,位于站 ai,bi 之间,往返均需要花费 ti 分钟 ...
- CSU 1808 地铁 (Dijkstra)
Description Bobo 居住在大城市 ICPCCamp. ICPCCamp 有 n 个地铁站,用 1,2,-,n 编号. m 段双向的地铁线路连接 n 个地铁站,其中第 i 段地铁属于 ci ...
- 湖南省第十二届大学生计算机程序设计竞赛 F 地铁 多源多汇最短路
1808: 地铁 Description Bobo 居住在大城市 ICPCCamp. ICPCCamp 有 n 个地铁站,用 1,2,…,n 编号. m 段双向的地铁线路连接 n 个地铁站,其中第 i ...
- CSU 1808:地铁(Dijkstra)
http://acm.csu.edu.cn/csuoj/problemset/problem?pid=1808 题意:…… 思路:和之前的天梯赛的一题一样,但是简单点. 没办法直接用点去算.把边看成点 ...
- CSU1808 地铁 —— dijkstra变形
题目链接:http://acm.csu.edu.cn/csuoj/problemset/problem?pid=1808 题解:由于中转线路需要花费一定的时间,所以一般的以顶点为研究对象的dijkst ...
随机推荐
- spring——获取ClassLoader
org.springframework.util包下的ClassUtils类有个静态方法:getDefaultClassLoader() 可以获取当前类加载器,如下: public static Cl ...
- VBS 重启 TP-Link 路由器
分享一个自己用的小工具,重启TP-Link路由器的,好像还是大学时候写的,献丑了. 其他路由器可能有些不同,但是思路都是差不多的. user = "admin" '路由器帐号 pa ...
- Arcgis10.1 Arcobject连接Oracel数据库
原来使用Arcgis9.3的版本,现在升级到了10.1遇到不少问题,原来初始化工作空间的代码无法正常运行了,修改后的代码如下: static void Test() { IPropertySet sd ...
- 线搜索(line search)方法
在机器学习中, 通常需要求某个函数的最值(比如最大似然中需要求的似然的最大值). 线搜索(line search)是求得一个函数\(f(x)\)的最值的两种常用迭代方法之一(另外一个是trust re ...
- spring 配置定时任务Scheduled
一:在spring配置的xml文件添加3条命名空间 xmlns:task="http://www.springframework.org/schema/task" xsi:sche ...
- 20155231 2016-2017-2 《Java程序设计》第8周学习总结
20155231 2016-2017-2 <Java程序设计>第8周学习总结 教材学习内容总结 学习目标 了解NIO 会使用Channel.Buffer与NIO2 会使用日志API.国际化 ...
- 20155236 2016-2017-2 《Java程序设计》第四周学习总结
20155236 2016-2017-2 <Java程序设计>第四周学习总结 教材学习内容总结 1.继承基本上就是避免多个类间重复定义共同行为. 继承的三个好处:减少代码冗余:维护变得简单 ...
- css的盒模型手机端兼容写法应该是啥样的呢?
前言:刚刚接触css3的盒模型,感觉对于解决水平垂直居中.固定宽度/高度和可变宽度/高度同时存在这样的问题很有效.但是最近在看一个腾讯手机端框架(Frozen UI )的时候发现一个很神奇的多行文字截 ...
- 解决java计算中double类型结果不一致问题,使用BigDecimal解决
一.需求:从数据表中读出一个double的数据,比如是3.5,没问题,但是如果再用3.5进行计算,比如乘以100,结果就是350了,而是35000000004 因为是浮点运算,所有语言中的浮点数都会有 ...
- mysql -> 用户管理&数据类型_04
用户权限,回收权限 数据类型 生产案例