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 ...
随机推荐
- 打包python脚本为exe的坎坷经历, by pyinstaller方法
打包python脚本为exe的坎坷经历, by pyinstaller方法 又应验了那句歌词. 不经历风雨, 怎么见得了彩虹. 安装过程略去不提, 仅提示: pip install pyinstall ...
- Spring容器事件、自定义事件
Spring容器内置事件,如容器的启动.停止.关闭.销毁等事件 <bean name="contextStartedHandler" class="com.nuts ...
- sql 恢复数据库
RESTORE DATABASE RoadFlowWebForm --数据库名称 FROM DISK = 'E:\WEBFORM2.5.1.bak' --bak文件路径 with replace, M ...
- 【Tomcat】Tomcat配置与优化(内存、并发、管理)【自己配置】
一.JVM内存配置优化 主要通过以下的几个jvm参数来设置堆内存的: -Xmx512m 最大总堆内存,一般设置为物理内存的1/4 -Xms512m 初始总堆内存,一般将它设置的和最大堆内存一样大,这样 ...
- ECMAScript——(二)
1.语法 区分大小写 变量是弱类型(定义变量时只用 var 运算符,可以将它初始化为任意值.) 每行结尾的分号可有可无(建议写上) 注释与Java一样 括号表示代码块 2.变量 变量可以不用声明,变量 ...
- jQuery学习(二) 自定义扩展函数
jQuery函数调用写法很优雅,在项目开发过程中,有需要自定义函数经常被使用到,将这些函数放置到项目ExtTool.js中,为了编码方式的统一,也希望这些自定义函数与jQuery函数一致的调用方式.在 ...
- video标签、audio标签
1.video标签 <video src="nans.mp4" controls="controls" autoplay="autoplay& ...
- git —— Feature分支
添加新功能时,新建feature分支 分支上开发完成后,再进行合并.最后删除feature分支 $ git checkout -b feature-vulcan 开发完毕后,切换回添加的分支,进行合并 ...
- django(2)基本指令
打开 Linux 或 MacOS 的 Terminal (终端)直接在 终端中输入这些命令(不是 python 的 shell中) 如果是 windows 用 cmd(开始 搜索 cmd 或者 快捷键 ...
- windows下redis服务操作
安装redis服务redis-server --service-install redis.windows.conf --service-name Redis26380 --loglevel verb ...