湖南省第十二届大学生计算机程序设计竞赛 F 地铁 多源多汇最短路
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
题解:
现在假设i号线在深度i的世界里跑
换线相当于换层
然后换乘站相当于一个垂直通道,拆出一些点放到对应的层里
然后按照深度从小到大连……
你从1楼上到3楼就和你从1楼上到2楼,再从2楼上到3楼是一样的
连边侯跑一发最短路就好了 ,spfa超时
感谢quailty的题解和代码
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<queue>
using namespace std;
#pragma comment(linker, "/STACK:102400000,102400000")
#define ls i<<1
#define rs ls | 1
#define mid ((ll+rr)>>1)
typedef long long LL;
const LL INF = (1LL<<)-;
const double Pi = acos(-1.0);
const int N = 1e5+, M = 1e6+, mod = 1e9+, inf = (<<)-; LL dist[N<<];
int vis[N<<];
struct Edge
{
int a,b,t;
Edge(int _a=,int _b=,int _t=) : a(_a), b(_b), t(_t) {}
};
struct qnode {
LL v,c;
qnode(LL _v=,LL _c=) : v(_v), c(_c) {}
bool operator < (const qnode &r) const
{
return c > r.c;
}
};
vector< Edge > tmp[N<<];
vector< pair<int,int > > G[N<<];
vector<pair<int ,int > > p[N<<];
void Add(int u,int v,int w) {
G[u].push_back(make_pair(v,w));
G[v].push_back(make_pair(u,w));
}
void init() {
for(int i = ; i < N; ++i) p[i].clear(), tmp[i].clear();
for(int i = ; i < * N; ++i) G[i].clear();
}
void Dij(int n,int u) {
for(int i = ; i <= n; ++i) dist[i] = INF, vis[i] = ;
priority_queue<qnode> q;
for(int i = ; i < p[u].size(); ++i) {
dist[p[u][i].first] = ;
q.push(qnode{p[u][i].first,});
}
while(!q.empty()) {
int k = q.top().v;
q.pop();
if(vis[k]) continue;
vis[k] = ;
for(int i = ; i < G[k].size(); ++i)
{
int v = G[k][i].first;
int c = G[k][i].second;
if(!vis[v] && dist[v] > dist[k] + c) {
dist[v] = dist[k] + c;
q.push(qnode{v,dist[v]});
}
}
}
}
int n,m;
int main() {
while(scanf("%d%d",&n,&m)!=EOF) {
init();
for(int i = ; i <= m; ++i) {
int a,b,c,t;
scanf("%d%d%d%d",&a,&b,&c,&t);
tmp[c].push_back(Edge(a,b,t));
}
int tot = ;
for(int i = ; i < N; ++i) {
for(int j = ; j < tmp[i].size(); ++j) {
int v[] = {tmp[i][j].a,tmp[i][j].b}, w = tmp[i][j].t;
for(int _=;_<;++_){
int u = v[_];
if(p[u].empty() || p[u].back().second < i) {
p[u].push_back(make_pair(++tot,i));
int s = p[u].size();
if(s > ) Add(p[u][s-].first,p[u][s-].first,p[u][s-].second-p[u][s-].second);
}
}
Add(p[v[]].back().first,p[v[]].back().first,w);
}
}
Dij(tot,);
LL ans = INF;
for(int i = ; i < p[n].size(); ++i)
ans = min( ans, dist[p[n][i].first]);
printf("%lld\n",ans);
}
return ;
}
湖南省第十二届大学生计算机程序设计竞赛 F 地铁 多源多汇最短路的更多相关文章
- 2016年湖南省第十二届大学生计算机程序设计竞赛---Parenthesis(线段树求区间最值)
原题链接 http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1809 Description Bobo has a balanced parenthes ...
- 2016年湖南省第十二届大学生计算机程序设计竞赛Problem A 2016 找规律归类
Problem A: 2016 Time Limit: 5 Sec Memory Limit: 128 MB Description 给出正整数 n 和 m,统计满足以下条件的正整数对 (a,b) ...
- 湖南省第十二届大学生计算机程序设计竞赛 B 有向无环图 拓扑DP
1804: 有向无环图 Time Limit: 5 Sec Memory Limit: 128 MBSubmit: 187 Solved: 80[Submit][Status][Web Board ...
- 湖南省第十二届大学生计算机程序设计竞赛 G Parenthesis
1809: Parenthesis Description Bobo has a balanced parenthesis sequence P=p1 p2…pn of length n and q ...
- 湖南省第十二届大学生计算机程序设计竞赛 A 2016
1803: 2016 Description 给出正整数 n 和 m,统计满足以下条件的正整数对 (a,b) 的数量: 1. 1≤a≤n,1≤b≤m; 2. a×b 是 2016 的倍数. In ...
- 【模拟】CSU 1807 最长上升子序列~ (2016湖南省第十二届大学生计算机程序设计竞赛)
题目链接: http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1807 题目大意: 给你一个长度为N(N<=105)的数列,数列中的0可以被其他数 ...
- 【最短路】【数学】CSU 1806 Toll (2016湖南省第十二届大学生计算机程序设计竞赛)
题目链接: http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1806 题目大意: N个点M条有向边,给一个时间T(2≤n≤10,1≤m≤n(n-1), ...
- 【树状数组】CSU 1811 Tree Intersection (2016湖南省第十二届大学生计算机程序设计竞赛)
题目链接: http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1811 题目大意: 一棵树,N(2<=N<=105)个节点,每个节点有一种颜 ...
- 【数学】CSU 1810 Reverse (2016湖南省第十二届大学生计算机程序设计竞赛)
题目链接: http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1810 题目大意: 一个长度为N的十进制数,R(i,j)表示将第i位到第j位翻转过来后的 ...
随机推荐
- POJ 2388(排序)
http://poj.org/problem?id=2388 题意:就N个数的中位数. 思路:用快排就行了.但我没用快排,我自己写了一个堆来做这个题.主要还是因为堆不怎么会,这个拿来练练手. #inc ...
- poj 2403
http://poj.org/problem?id=2403 题意:就是给你m个单词,以及n段对话.每一个单词都有所对应的价值.求对话中的价值总和 题解:很简单,就是用单词和价值对应起来,然后再寻找就 ...
- PHP javascript cookie
2015-07-30 16:54:58 ................................cao!!!! 汉字, 邮箱的@符号 容易出错 PHP setcookie 的时候, 不要url ...
- ACM/ICPC 之 Bellman Ford练习题(ZOJ1791(POJ1613))
这道题稍复杂一些,需要掌握字符串输入的处理+限制了可以行走的时间. ZOJ1791(POJ1613)-Cave Raider //限制行走时间的最短路 //POJ1613-ZOJ1791 //Time ...
- RegisterDllAndOcx.bat -批量注册当前文件夹中的dll和ocx
批量注册当前文件夹中的dll和ocx 新建文件:RegisterDllAndOcx.bat @echo off echo hello,girl~~ for %%i in (*.dll *.ocx) ...
- ios waxpatch lua语法
Wax Lua 使用方法 说一下 Wax 的特点,它支持你在脚本里使用任何 OC 的类,同样也支持你创建一个类. 使用一个类时你会这样使用: 1 2 NSString -- Returns the N ...
- [Android Pro] Java进阶学习:jar打包详解
jar文件听说过吗,没有?或者陌生!好,没关系,这就是我们的第一站:打包发布. 为什么会有这个玩意呢,首先,这是jar的全称:JavaTM Archive (JAR) file,是的,就是java存档 ...
- python基础——返回函数
python基础——返回函数 函数作为返回值 高阶函数除了可以接受函数作为参数外,还可以把函数作为结果值返回. 我们来实现一个可变参数的求和.通常情况下,求和的函数是这样定义的: def calc_ ...
- NYOJ题目436sum of all integer numbers
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAr0AAAHKCAIAAACBiWRrAAAgAElEQVR4nO3dP1LjSts34G8T5CyEFB
- Hibernate中一对多和多对一关系
1.单向多对一和双向多对一的区别? 只需要从一方获取另一方的数据时 就使用单向关联双方都需要获取对方数据时 就使用双向关系 部门--人员 使用人员时如果只需要获取对应部门信息(user.getdept ...