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的更多相关文章

  1. 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 ...

  2. 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 ...

  3. 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 ...

  4. 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 ...

  5. Hdu 4725 The Shortest Path in Nya Graph (spfa)

    题目链接: Hdu 4725 The Shortest Path in Nya Graph 题目描述: 有n个点,m条边,每经过路i需要wi元.并且每一个点都有自己所在的层.一个点都乡里的层需要花费c ...

  6. 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 ...

  7. 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 ...

  8. 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 题意: 在一个图中跑最 ...

  9. 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 ...

随机推荐

  1. Moodle配置

    Moodle配置 1.   内部设置 在 Moodle 站点管理员界面中有一系列的配置页面(可以从'设置' 块中访问 '网站管理'区).这里有一些重要的系统设置,你需要进行检查. 根据提示信息并结合实 ...

  2. svn update解决冲突

    (p) postpone 暂时推后处理,我可能要和那个和我冲突的家伙商量一番 (df) diff-full 把所有的修改列出来,比比看 (e) edit 直接编辑冲突的文件 (mc) mine-con ...

  3. ICPC2017 Urumqi - K - Sum of the Line

    题目描述 Consider a triangle of integers, denoted by T. The value at (r, c) is denoted by Tr,c , where 1 ...

  4. 数据结构:Rope

    以BZOJ1507为例,这里仅仅展示动态区间问题的一些典型操作,包括插入删除和修改,查询的话不支持按顺序查询 使用起来很简单很方便 #include<cstdio> #include< ...

  5. Linux 下访问Windows共享目录

    5.安装cifs-utils软件包 # yum install cifs-utils 貌似可以不用安装这个包. 6.在Linux下创建一个挂载点 # mkdir  /mnt/Windows 7.挂载W ...

  6. redhat 7 配置yum本地源

    http://www.unixarena.com/2015/04/how-to-create-the-yum-repository-on-rhel-7.html   1. 在虚拟机上挂上cd 2. m ...

  7. 函数式编程--响应式编程 ---android应用例子

    RxJava implements this operator as create. It is good practice to check the observer’s isUnsubscribe ...

  8. 用 Docker 来构建 Jumpserver

    说明: 项目从 [ Jumpserver 官方 ] fork 而来. 主要更新: OS: ubuntu:18.04 优化了 Dockerfile Jumpserver 版本: 1.4.0 redis ...

  9. java===java基础学习(14)---封装

    package dog; public class Demo4 { public static void main(String []args) { Worker w1= new Worker(&qu ...

  10. Linux时间子系统之一:clock source(时钟源)【转】

    转自:http://blog.csdn.net/droidphone/article/details/7975694 clock source用于为linux内核提供一个时间基线,如果你用linux的 ...