首页 > 其他分享 >CSU 1808 地铁

CSU 1808 地铁

时间:2022-11-09 19:33:57浏览次数:36  
标签:sz int dis tot 1808 地铁 CSU include define


Description


 Bobo 居住在大城市 ICPCCamp。



i 号线,位于站 a i,b i 之间,往返均需要花费 t i 分钟(即从 a i 到 b i 需要 t i 分钟,从 b i 到 a i 也需要 t i分钟)。



i-c j



Bobo 想知道从地铁站 1 到地铁站 n 所需要花费的最小时间。



Input


输入包含不超过 20 组数据。



5,1≤m≤10 5).



i,b i,c i,t i (1≤a i,b i,c i≤n,1≤t i≤10 9).



保证存在从地铁站 1 到 n 的地铁线路(不一定直达)。



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

#include<set>
#include<map>
#include<ctime>
#include<cmath>
#include<stack>
#include<queue>
#include<bitset>
#include<cstdio>
#include<string>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<functional>
#define rep(i,j,k) for (int i = j; i <= k; i++)
#define per(i,j,k) for (int i = j; i >= k; i--)
#define loop(i,j,k) for (int i = j;i != -1; i = k[i])
#define lson x << 1, l, mid
#define rson x << 1 | 1, mid + 1, r
#define ff first
#define ss second
#define mp(i,j) make_pair(i,j)
#define pb push_back
#define pii pair<int,LL>
#define in(x) scanf("%d", &x);
using namespace std;
typedef long long LL;
const int low(int x) { return x&-x; }
const double eps = 1e-9;
const int INF = 0x7FFFFFFF;
const int mod = 1e9 + 7;
const int N = 6e5 + 10;
struct point
{
int x, y, c, v, q;
void read()
{
scanf("%d%d%d%d", &x, &y, &c, &v);
q = 0; if (x > y) swap(x, y);
}
bool operator<(const point &a)const
{
return c > a.c;
}
}g[N];
int n, m, l, r, tot;
int ft[N], nt[N], u[N], v[N], sz;
int Ft[N], Nt[N], U[N], Sz;
struct poi
{
LL x, y;
poi(LL x, LL y) :x(x), y(y) {}
bool operator<(const poi &a)const
{
return y > a.y;
}
};
LL dis[N];

void add(int x, int y, int z)
{
u[sz] = y; v[sz] = z; nt[sz] = ft[x]; ft[x] = sz++;
u[sz] = x; v[sz] = z; nt[sz] = ft[y]; ft[y] = sz++;
}

int main()
{
while (scanf("%d%d", &n, &m) != EOF)
{
tot = sz = Sz = 0;
rep(i, 1, n) Ft[i] = -1;
rep(i, 1, m) g[i].read();
sort(g + 1, g + m + 1);
rep(i, 1, m)
{
U[Sz] = i; Nt[Sz] = Ft[g[i].x]; Ft[g[i].x] = Sz++;
U[Sz] = i; Nt[Sz] = Ft[g[i].y]; Ft[g[i].y] = Sz++;
}
rep(i, 1, n)
{
if (i == n) r = tot;
int col = 0, bef = 0;
loop(j, Ft[i], Nt)
{
point &q = g[U[j]];
if (q.c != col)
{
ft[++tot] = -1;
if (col) add(bef, tot, q.c - col);
bef = tot; col = q.c;
}
if (q.x < i) add(bef, q.q, q.v); else q.q = bef;
}
if (i == 1) l = tot;
}

LL ans = -1;
rep(i, l + 1, tot) dis[i] = -1;
priority_queue<poi> p;
rep(i, 1, l) p.push(poi(i, dis[i] = 0));
while (!p.empty())
{
poi q = p.top(); p.pop();
loop(i, ft[q.x], nt)
{
if (dis[u[i]] == -1 || dis[u[i]] > q.y + v[i])
{
p.push(poi(u[i], dis[u[i]] = q.y + v[i]));
}
}
}
per(i, tot, r + 1) ans = ans == -1 ? dis[i] : min(ans, dis[i]);
printf("%lld\n", ans);
}
return 0;
}

标签:sz,int,dis,tot,1808,地铁,CSU,include,define
From: https://blog.51cto.com/u_15870896/5838618

相关文章

  • CSU 1810 Reverse
    Description1 d2…dn1…di-1 dj dj-1…di dj+1 dj+2…dn.Bobowouldliketofind9+7).InputTheinputcontains......
  • CSU 1809 Parenthesis
    Description1 p2…pnai andpbiParenthesissequenceSisbalancedifandonlyif:Sisempty;orthereexists balanced parenthesi......
  • CSU 1804 有向无环图
    DescriptionBobo有一个n个点,m条边的有向无环图(即对于任意点v,不存在从点v开始、点v结束的路径)。为了方便,点用1,2,…,n编号。设count(x,y)表示点x......
  • CSU 1803 2016
    Description 给出正整数n和m,统计满足以下条件的正整数对(a,b)的数量:1.1≤a≤n,1≤b≤m;2.a×b是2016的倍数。Input......
  • 北京地铁车站系统
       chezhan.javapackagebean;publicclasschezhan{intID;Stringname;Stringno1;Stringno2;Stringno3;Stringno4;publicintgetID(){ret......
  • 关于安科瑞火灾监控系统在地铁供配电系统中的应用
    陈盼安科瑞电气股份有限公司上海嘉定201801 【摘要】在地铁车站供配电系统中使用电气火灾监控系统对监控设备工况、预防电气火灾十分重要,地铁公司作为企业,还需充分考虑前......
  • 【XSY3396】地铁(平面图与对偶图,最小割)
    题意:给一张平面图,满足这张平面图的对偶图是一棵树,有若干限制,形如“若经过点\(x\)则必须要经过点\(y\)”,求\(1\simn\)的最短路。由于平面图与其对偶图互为对偶,所以......
  • csu 1554: SG Value 思维题
    ​​http://acm.csu.edu.cn/csuoj/problemset/problem?pid=1554​​这题在比赛的时候居然没想出来,然后发现居然是做过的题目的变种!!!!先不考虑插入操作,就给定一堆数字,求出不能......
  • D - Simple String CSU - 1550
    ​​http://acm.csu.edu.cn/csuoj/problemset/problem?pid=1550​​很久都没补这题,最近想学网络流,就看看,队友以前用网络流过的,Orz,但是这题只需要简单的判断,可能想起来有点麻......
  • scau 18087 开始我是拒接的 mobius
    其实有一个很有用的技巧就是,把gcd=4的贡献,压去gcd=2时的贡献,就不需要考虑这么多的了。为什么可以把gcd=4的,压去gcd=2的呢,gcd=12的,压去gcd=6的去算呢,其实这就是m......