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. arp协议及简单应用

    1:什么是arp协议 参考文章:http://blog.csdn.net/tigerjibo/article/details/7351992 全称是:Address Resolution Protoc ...

  2. 正确理解WPF中的TemplatedParent

    (注:Logical Tree中文称为逻辑树,Visual Tree中文称为可视化树或者视觉树,由于名称不是很统一,文中统一用英文名称代表两个概念,况且VisualTreeHelper和Logical ...

  3. [技巧篇]10.那些年我们一起优化过的MyEclipse8.6

    这里里面是针对于四海的给位学生预留的视频,请自行下载,我希望对大家有所帮助 我这里使用了百度网盘,这里的东西还是比较多的!如果喜欢请关注我,当好胖先生的粉丝 链接:http://pan.baidu.c ...

  4. nodejs formidable混合表单提交

    废话不多说,直接上代码: 前端页面: <!DOCTYPE html><html><head><link rel=’stylesheet’ href=’/sty ...

  5. Large Class--过大的类--要重构的信号

    如果想利用单个类做太多事情,其内往往就会出现太多实例变量.一旦如此,Duplicated Code也就接踵而至.     解决方法:     1.将类内彼此相关的变量,将它们放在一起.使用Extrac ...

  6. cocos2dx中启用lua脚本

    AppDelegate 的 applicationDidFinishLaunching 方法中加载Lua引擎 bool AppDelegate::applicationDidFinishLaunchi ...

  7. 【洛谷 P1129】 [ZJOI2007]矩阵游戏 (二分图匹配)

    题目链接 看到题目肯定首先会想到搜索. 然鹅数据范围\(n<=200\)这么大(其实也不算太大),肯定是不行的. 如果\((i,j)\)是\(1\),从\(i\)向\(j\)连一条边,表示第\( ...

  8. Different Integers(牛客多校第一场+莫队做法)

    题目链接:https://www.nowcoder.com/acm/contest/139/J 题目: 题意:给你n个数,q次查询,对于每次查询得l,r,求1~l和r~n元素得种类. 莫队思路:1.将 ...

  9. ASP.NET 简单鼠标右键效果contextmenutrip

    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx. ...

  10. poj 1062 昂贵的聘礼 (dijkstra最短路)

    题目链接:http://poj.org/problem?id=1062 昂贵的聘礼 Time Limit: 1000MS   Memory Limit: 10000K Total Submission ...