AC日记——The Shortest Path in Nya Graph hdu 4725
思路:
拆点建图跑最短路;
代码:
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
#define maxn 200005
#define maxn_ 400005
#define maxque 2000005
#define INF 0x3f3f3f3f
int n,m,head[maxn_],E[maxque],V[maxque],W[maxque];
int cnt=,que[maxque],val,dis[maxn_];
bool if_[maxn_];
inline void in(int &now)
{
char Cget=getchar();now=;
while(Cget>''||Cget<'')Cget=getchar();
while(Cget>=''&&Cget<='')
{
now=now*+Cget-'';
Cget=getchar();
}
}
inline void edge_add(int u,int v,int w)
{
E[++cnt]=head[u],V[cnt]=v,W[cnt]=w,head[u]=cnt;
}
int main()
{
int T;in(T);
for(int t=;t<=T;t++)
{
memset(head,,sizeof(head));
in(n),in(m),in(val),cnt=;
int pos,u,v,w;
for(int i=;i<=n;i++)
{
in(pos);
edge_add(pos+n,i,);
edge_add(i,pos+n+n,);
}
for(pos=;pos<n;pos++)
{
edge_add(pos+n+n,pos++n,val);
edge_add(pos+n+n+,pos+n,val);
}
for(int i=;i<=m;i++)
{
in(u),in(v),in(w);
edge_add(u,v,w);
edge_add(v,u,w);
}
for(int i=;i<=n*;i++)dis[i]=INF,if_[i]=false;
int h=maxque>>,tail=h+,now;dis[]=,if_[]=true,que[h]=;
while(h<tail)
{
now=que[h++],if_[now]=false;
for(int i=head[now];i;i=E[i])
{
if(dis[now]+W[i]<dis[V[i]])
{
dis[V[i]]=dis[now]+W[i];
if(!if_[V[i]])
{
if_[V[i]]=true;
if(dis[V[i]]<dis[que[h]]&&h<tail) que[--h]=V[i];
else que[tail++]=V[i];
}
}
}
}
printf("Case #%d: %d\n",t,dis[n]==INF?-:dis[n]);
}
return ;
}
AC日记——The Shortest Path in Nya Graph hdu 4725的更多相关文章
- The Shortest Path in Nya Graph HDU - 4725
Problem Description This is a very easy problem, your task is just calculate el camino mas corto en ...
- HDU 4725 The Shortest Path in Nya Graph(构图)
The Shortest Path in Nya Graph Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K ...
- HDU 4725 The Shortest Path in Nya Graph (最短路)
The Shortest Path in Nya Graph Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K ...
- HDU4725:The Shortest Path in Nya Graph(最短路)
The Shortest Path in Nya Graph Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K ...
- Hdu 4725 The Shortest Path in Nya Graph (spfa)
题目链接: Hdu 4725 The Shortest Path in Nya Graph 题目描述: 有n个点,m条边,每经过路i需要wi元.并且每一个点都有自己所在的层.一个点都乡里的层需要花费c ...
- HDU 4725 The Shortest Path in Nya Graph [构造 + 最短路]
HDU - 4725 The Shortest Path in Nya Graph http://acm.hdu.edu.cn/showproblem.php?pid=4725 This is a v ...
- HDU 4725 The Shortest Path in Nya Graph
he Shortest Path in Nya Graph Time Limit: 1000ms Memory Limit: 32768KB This problem will be judged o ...
- HDU-4725 The Shortest Path in Nya Graph (拆点+dji)
HDU 4725 The Shortest Path in Nya Graph : http://acm.hdu.edu.cn/showproblem.php?pid=4725 题意: 在一个图中跑最 ...
- hdu 4725 The Shortest Path in Nya Graph (最短路+建图)
The Shortest Path in Nya Graph Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K ...
随机推荐
- arm架构与体系结构
1.cpu与soc 内核版本号与soc版本号由arm公司确定. 芯片型号由各半导体公司确定. soc包括cpu与一些基本内设.(一般提到CPU都指的是soc,实际上cpu只是soc的一部分). RIS ...
- 希尔排序Shell sort
希尔排序Shell Sort是基于插入排序的一种改进,同样分成两部分, 第一部分,希尔排序介绍 第二部分,如何选取关键字,选取关键字是希尔排序的关键 第一块希尔排序介绍 准备待排数组[6 2 4 1 ...
- python检测硬盘脚本
#!/usr/bin/env python # _*_coding:utf-8_*_ import os import sys import statvfs def main(): '''deamon ...
- ReaderWriterLockSlim 类
今天在看Nop源码时,PluginManager中用到了ReaderWriterLockSlim类,于是简单做个笔记. ReaderWriterLockSlim 表示用于管理资源访问的锁定状态,可实现 ...
- java修饰符——transient
一.背景 上星期去CRM上开发一个功能,该系统里面有自动分页,需要在实体类里加入一个分页变量 // 分页 private PageInfo pageInfo = new PageInfo(); 这个本 ...
- 【51NOD-0】1106 质数检测
[算法]数学 #include<cstdio> #include<cmath> bool ok(int x) { int m=(int)sqrt(x+0.5); ;i<= ...
- Spring 框架的设计理念与设计模式分析(山东数漫江湖)
Spring 的骨骼架构 Spring 总共有十几个组件,但是真正核心的组件只有几个,下面是 Spring 框架的总体架构图: 图 1 .Spring 框架的总体架构图 从上图中可以看出 Spring ...
- 【洛谷 P2742】【模板】二维凸包
题目链接 二维凸包板子..有时间会补总结的. #include <cstdio> #include <cmath> #include <algorithm> usi ...
- 【洛谷 P2303】 [SDOi2012]Longge的问题 (欧拉函数)
题目链接 题意:求\(\sum_{i=1}^{n}\gcd(i,n)\) 首先可以肯定,\(\gcd(i,n)|n\). 所以设\(t(x)\)表示\(gcd(i,n)=x\)的\(i\)的个数. 那 ...
- Drainage Ditches(POJ1273+网络流+Dinic+EK)
题目链接:poj.org/problem?id=1273 题目: 题意:求最大流. 思路:测板子题,分别用Dinic和EK实现(我的板子跑得时间均为0ms). Dinic代码实现如下: #includ ...