4725

思路:

  拆点建图跑最短路;

代码:

  1. #include <cstdio>
  2. #include <cstring>
  3. #include <iostream>
  4. #include <algorithm>
  5. using namespace std;
  6. #define maxn 200005
  7. #define maxn_ 400005
  8. #define maxque 2000005
  9. #define INF 0x3f3f3f3f
  10. int n,m,head[maxn_],E[maxque],V[maxque],W[maxque];
  11. int cnt=,que[maxque],val,dis[maxn_];
  12. bool if_[maxn_];
  13. inline void in(int &now)
  14. {
  15. char Cget=getchar();now=;
  16. while(Cget>''||Cget<'')Cget=getchar();
  17. while(Cget>=''&&Cget<='')
  18. {
  19. now=now*+Cget-'';
  20. Cget=getchar();
  21. }
  22. }
  23. inline void edge_add(int u,int v,int w)
  24. {
  25. E[++cnt]=head[u],V[cnt]=v,W[cnt]=w,head[u]=cnt;
  26. }
  27. int main()
  28. {
  29. int T;in(T);
  30. for(int t=;t<=T;t++)
  31. {
  32. memset(head,,sizeof(head));
  33. in(n),in(m),in(val),cnt=;
  34. int pos,u,v,w;
  35. for(int i=;i<=n;i++)
  36. {
  37. in(pos);
  38. edge_add(pos+n,i,);
  39. edge_add(i,pos+n+n,);
  40. }
  41. for(pos=;pos<n;pos++)
  42. {
  43. edge_add(pos+n+n,pos++n,val);
  44. edge_add(pos+n+n+,pos+n,val);
  45. }
  46. for(int i=;i<=m;i++)
  47. {
  48. in(u),in(v),in(w);
  49. edge_add(u,v,w);
  50. edge_add(v,u,w);
  51. }
  52. for(int i=;i<=n*;i++)dis[i]=INF,if_[i]=false;
  53. int h=maxque>>,tail=h+,now;dis[]=,if_[]=true,que[h]=;
  54. while(h<tail)
  55. {
  56. now=que[h++],if_[now]=false;
  57. for(int i=head[now];i;i=E[i])
  58. {
  59. if(dis[now]+W[i]<dis[V[i]])
  60. {
  61. dis[V[i]]=dis[now]+W[i];
  62. if(!if_[V[i]])
  63. {
  64. if_[V[i]]=true;
  65. if(dis[V[i]]<dis[que[h]]&&h<tail) que[--h]=V[i];
  66. else que[tail++]=V[i];
  67. }
  68. }
  69. }
  70. }
  71. printf("Case #%d: %d\n",t,dis[n]==INF?-:dis[n]);
  72. }
  73. return ;
  74. }

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. C++之tinyXML的使用详解

    tinyXML一款很优秀的操作C++类库,文件不大,但方法很丰富,和apache的Dom4j可以披靡啊!习惯了使用java类库的我看到这么丰富的c++类库,很高兴!它使用很简单,只需要拷贝几个文件到你 ...

  2. python删除文件

    删除qq文件夹中2013年12-31之前的文件import os import time import datetime timeline = datetime.datetime(,,) tl = t ...

  3. 【IntelliJ IDEA 12使用】导入外部包

    以前用eclipse,现在用IntelliJ IDEA,发现它确实是个很不错的工具. 用IntelliJ IDEA12这个版本导入外部JAR包,这样来操作,打开Project Structure,在m ...

  4. HDU2833 最短路 floyd

    WuKong Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Subm ...

  5. [Luogu 1160] 队列安排

    Luogu 1160 队列安排 链表H2O H2O H2O模板. 太久不写链表,忘干净了,竟调了半个晚上. 保留备用. #include <cstdio> #include <cst ...

  6. VM 脚本回快照和开关机

    #Import PowerCLI*Get-Module -ListAvailable PowerCLI* | Import-Module #Resolve login issueSet-PowerCL ...

  7. 安装显卡后蓝屏0x00000116解决办法

    1. 亲自遇到蓝屏的问题. 2. 进入安全模式后重装系统,成功. 3. 安装驱动,软件没毛病.安装显卡驱动后,蓝屏. 4. 查看蓝屏错误代码0x00000116, 百度后查看到是显卡驱动的问题. 5. ...

  8. Vuejs - 工欲善其事必先利其器

    既然是实战,怎离不开项目开发的环境呢?先给大家推荐下我的个人开发环境: 硬件设备:Mac OSX编译器:Visual Studio Code命令行工具:iTerm2调试工具:Chrome Dev to ...

  9. perl发送post数据

    把post数据写进一个匿名数组里就行 #!/usr/bin/env perl -w use strict; use LWP::UserAgent; my $ua = LWP::UserAgent-&g ...

  10. in_device结构和in_ifaddr结构

    /* ip配置块 */ struct in_device { /* 二层设备 */ struct net_device *dev; /* 引用计数 */ atomic_t refcnt; /* 是否正 ...