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核心编程——Chapter15
正则表达式在脚本语言里是最重要的一部分,这部分的题目真的不容怠慢. 开始这部分的题目的解答! 15.1识别下列字符串:bat,bit,but,hat,hit和hut. >>> imp ...
- 最长递增子序列(LIS)(转)
最长递增子序列(LIS) 本博文转自作者:Yx.Ac 文章来源:勇幸|Thinking (http://www.ahathinking.com) --- 最长递增子序列又叫做最长上升子序列 ...
- 内核:为了fan的健康,我的重新编译记录
email: jiqingwu@gmail.com date: 2008-02-13 关键词:ubuntu cpu cpufreqd cpufrequtils 编译 内核 装上ubuntu7.10后, ...
- Session详解、ASP.NET核心知识(8)
介绍一下Session 1.作用 Cookie是存在客户端,Session是存在服务器端,目的是一样的:保存和当前客户端相关的数据(当前网站的任何一个页面都能取到Session). 在本篇博文的姊妹篇 ...
- POJ 3255 Roadblocks (次短路 SPFA )
题目链接 Description Bessie has moved to a small farm and sometimes enjoys returning to visit one of her ...
- Python raw_input和input总结 在版本2和版本3中的区别
Python 2.3.4 (#1, Feb 2 2005, 11:44:13) [GCC 3.4.3 20041212 (Red Hat 3.4.3-9.EL4)] on linux2 Type &q ...
- 通过BurpSuite和sqlmap配合对dvwa进行sql注入测试和用户名密码暴力破解
0x1 工具和环境介绍 dvwa:渗透测试环境 BurpSuite:强大的WEB安全测试工具 sqlmap:强大的sql注入工具 以上工具和环境都在kali linux上安装和配置. 0x2 步骤说明 ...
- docker 错误排查:无法进入容器.
docker 错误排查:无法进入容器. #docker exec -it 3c1d bash rpc error: code = 2 desc = oci runtime error: exec fa ...
- Fiddler是最强大最好用的Web调试工具
Fiddler是最强大最好用的Web调试工具之一,它能记录所有客户端和服务器的http和https请求,允许你监视,设置断点,甚至修改输入输出数据. 使用Fiddler无论对开发还是测试来说,都有很大 ...
- 【Educational Codeforces Round28】
咸鱼选手发现自己很久不做cf了,晚节不保. A.Curriculum Vitae 枚举一下间断点的位置. #include<bits/stdc++.h> using namespace s ...