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 ...
随机推荐
- @RequestParam 注解的使用
@RequestParam 注解的使用 前言 在SpringMvc后台进行获取数据,一般是两种. 1.request.getParameter(“参数名”) 2.用@RequestParam注解获取 ...
- String类的用法
练习如何创建一个类. package create; public class Newstring { String aa; public Newstring() { // TODO Auto-gen ...
- Codeforces Round #332 (Div. 2)B. Spongebob and Joke
B. Spongebob and Joke time limit per test 2 seconds memory limit per test 256 megabytes input standa ...
- HDU 5538 (水不水?)
House Building Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others) ...
- 003.关于数组的操作 [growing]
1.获取数组的长度 #include<iostream> using namespace std; template<class T> int length(T& ar ...
- 手脱ASProtect v1.23 RC1(无Stolen Code)
1.载入PEID ASProtect v1.23 RC1 2.载入OD,不勾选内存访问异常,其他异常全部勾选 > 01C04200 push 跑跑排行.0042C001 ; //入口处 E8 c ...
- 允许Traceroute探测
允许Traceroute探测 漏洞描述: 允许Traceroute探测 漏洞描述 本插件使用Traceroute探测来获取扫描器与远程主机之间的路由信息.攻击者也可以利用这些信息来了解目标网络的网络拓 ...
- [Leetcode] LRU 算法实现
Design and implement a data structure for Least Recently Used (LRU) cache. It should support the fol ...
- linux部署j2eeweb工程涉及到的指令
1.查看java进程: ps -e | grep java; 可以获取到java进程的进程号. 或: ps -ef | grep java; 可以查看到详细的进程信息 2.杀死java进程 kill ...
- 选择排序Selection sort
顾名思意,就是直接从待排序数组里选择一个最小(或最大)的数字,每次都拿一个最小数字出来, 顺序放入新数组,直到全部拿完 再简单点,对着一群数组说,你们谁最小出列,站到最后边 然后继续对剩余的无序数组说 ...