记录编号 36587 评测结果 AAAAAAAAAA
题目名称 城市 最终得分 100
用户昵称 Gravatarkaaala 是否通过 通过
代码语言 C++ 运行时间 0.383 s
提交时间 2012-03-15 08:38:49 内存使用 0.35 MiB
显示代码纯文本
  1. #include<iostream>
  2. #include<cstdio>
  3. #include<cstdlib>
  4. #include<cmath>
  5. #include<cstring>
  6. #include<algorithm>
  7. #include<queue>
  8.  
  9. using namespace std;
  10.  
  11. const int oo=~0u>>2;
  12.  
  13. struct edge
  14. {
  15. int t,cost;
  16. edge *next;
  17. edge(int _t,int _cost,edge *_next):t(_t),cost(_cost),next(_next){}
  18. }*Map[10010];
  19.  
  20. int N,M,U,V,S,F[10010];
  21.  
  22. void addedge(int s,int t,int cost)
  23. {
  24. Map[s]=new edge(t,cost,Map[s]);
  25. Map[t]=new edge(s,cost,Map[t]);
  26. }
  27.  
  28. bool djs(int x)
  29. {
  30. bool vis[10010];
  31. int dist[10010];
  32. priority_queue<pair<int,int> >heap;
  33. if(F[U]>x)
  34. return true;
  35. memset(vis,0,sizeof(vis));
  36. for(int i=1;i<=N;i++)
  37. dist[i]=oo;
  38. dist[U]=0;
  39. heap.push(make_pair(0,U));
  40. while(!heap.empty())
  41. {
  42. int u=heap.top().second;
  43. heap.pop();
  44. if(!vis[u])
  45. {
  46. vis[u]=true;
  47. for(edge *p=Map[u];p;p=p->next)
  48. {
  49. int t=p->t,cost=p->cost;
  50. if(F[t]>x)
  51. continue;
  52. if(!vis[t]&&dist[t]>dist[u]+cost)
  53. {
  54. dist[t]=dist[u]+cost;
  55. heap.push(make_pair(-dist[t],t));
  56. }
  57. }
  58. }
  59. }
  60. if(dist[V]>S)
  61. return true;
  62. else
  63. return false;
  64. }
  65.  
  66. int main()
  67. {
  68. freopen("cost.in","r",stdin);
  69. freopen("cost.out","w",stdout);
  70. scanf("%d%d%d%d%d",&N,&M,&U,&V,&S);
  71. int l,r;
  72. for(int i=1;i<=N;i++)
  73. {
  74. scanf("%d",&F[i]);
  75. if(F[i]>r)
  76. r=F[i];
  77. if(F[i]<l)
  78. l=F[i];
  79. }
  80. for(int i=1;i<=M;i++)
  81. {
  82. int a,b,c;
  83. scanf("%d%d%d",&a,&b,&c);
  84. addedge(a,b,c);
  85. }
  86. if(djs(r))
  87. {
  88. printf("-1\n");
  89. return 0;
  90. }
  91. while(l<r)
  92. {
  93. int mid=(l+r)>>1;
  94. if(!djs(mid))
  95. r=mid;
  96. else
  97. l=mid+1;
  98. }
  99. printf("%d\n",l);
  100. return 0;
  101. }