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. ubuntu切割mp3文件

    ffmpeg -i InputFile -vn -acodec copy -ss 00:00:00 -t 00:01:32 OutPutFile

  2. ASP.Net初级学习一(基本语句入门)

    <body > <form method="post" action="program.ashx"> <input type=&q ...

  3. 线程池 ------ linux C实现

    大多数的网络服务器,包括Web服务器都具有一个特点,就是单位时间内必须处理数目巨大的连接请求,但是处理时间却是比较短的.在传统的多线程服务器模型中是这样实现的:一旦有个请求到达,就创建一个新的线程,由 ...

  4. solr集群安装部署

    一.安装部署zookeeper集群 zookeeper集群 二.solr集群部署 集群配置 IP | 节点名称 | 环境 --- | --- | --- 192.168.137.128 | 192.1 ...

  5. nodejs+react构建仿知乎的小Demo

    一.命令行进入指定项目文件夹 二.相关命令安装环境和项目工具 npm init npm install react -- save npm install -g gulp npm install -- ...

  6. 如何根据域名来得到对应的IP

    如何根据域名来得到对应的IP呢? windows下打开cmd窗口,然后ping.如下图: 这样就可以看到IP了. 如何查看自己电脑对应的IP? 当通过代理上网时,可能无法通过网络连接信息查看自己电脑的 ...

  7. python学习笔记(三)之变量和字符串

    在其他语言中,变量就是有名字的存储区,可以将值存储在变量中,也即内存中.在Python中略有不同,python并不是将值存储在变量中,更像是把名字贴在值上边.所以,有些python程序员会说pytho ...

  8. IT培训班123

    最近20年,IT行业一直处于上升期,程序员的工资越来越高了,年薪几十万的程序员大有人在.根据国家统计局发布的2016年各行业平均工资报表,程序员已经是工资最高的一个群体,超过了金融行业. IT行业的火 ...

  9. eCharts_数据过多底部滚动条实现数据展示

    效果图: 实现原理: 1.添加dataZoom属性 效果实现代码: <!DOCTYPE html> <html> <head> <meta charset=& ...

  10. ES6新增的let与const

    1.const 声明常量,一旦声明必须立马赋值,否则报错 const PI = 3.14 const PI; //报错:Uncaught SyntaxError: Missing initialize ...