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 ...
随机推荐
- C++之tinyXML的使用详解
tinyXML一款很优秀的操作C++类库,文件不大,但方法很丰富,和apache的Dom4j可以披靡啊!习惯了使用java类库的我看到这么丰富的c++类库,很高兴!它使用很简单,只需要拷贝几个文件到你 ...
- python删除文件
删除qq文件夹中2013年12-31之前的文件import os import time import datetime timeline = datetime.datetime(,,) tl = t ...
- 【IntelliJ IDEA 12使用】导入外部包
以前用eclipse,现在用IntelliJ IDEA,发现它确实是个很不错的工具. 用IntelliJ IDEA12这个版本导入外部JAR包,这样来操作,打开Project Structure,在m ...
- HDU2833 最短路 floyd
WuKong Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Subm ...
- [Luogu 1160] 队列安排
Luogu 1160 队列安排 链表H2O H2O H2O模板. 太久不写链表,忘干净了,竟调了半个晚上. 保留备用. #include <cstdio> #include <cst ...
- VM 脚本回快照和开关机
#Import PowerCLI*Get-Module -ListAvailable PowerCLI* | Import-Module #Resolve login issueSet-PowerCL ...
- 安装显卡后蓝屏0x00000116解决办法
1. 亲自遇到蓝屏的问题. 2. 进入安全模式后重装系统,成功. 3. 安装驱动,软件没毛病.安装显卡驱动后,蓝屏. 4. 查看蓝屏错误代码0x00000116, 百度后查看到是显卡驱动的问题. 5. ...
- Vuejs - 工欲善其事必先利其器
既然是实战,怎离不开项目开发的环境呢?先给大家推荐下我的个人开发环境: 硬件设备:Mac OSX编译器:Visual Studio Code命令行工具:iTerm2调试工具:Chrome Dev to ...
- perl发送post数据
把post数据写进一个匿名数组里就行 #!/usr/bin/env perl -w use strict; use LWP::UserAgent; my $ua = LWP::UserAgent-&g ...
- in_device结构和in_ifaddr结构
/* ip配置块 */ struct in_device { /* 二层设备 */ struct net_device *dev; /* 引用计数 */ atomic_t refcnt; /* 是否正 ...