记录编号 122251 评测结果 AAAAAAAAAA
题目名称 城市 最终得分 100
用户昵称 GravatarHouJikan 是否通过 通过
代码语言 C++ 运行时间 0.233 s
提交时间 2014-09-22 21:41:40 内存使用 0.58 MiB
显示代码纯文本
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <list>
#include <vector>
#include <ctime>
#include <iterator>
#include <functional>
#define pritnf printf
#define scafn scanf
#define For(i,j,k) for(int i=(j);i<=(k);(i)++)
using namespace std;
typedef long long LL;
typedef unsigned int Uint; 
const int INF=1000000000;
//==============struct declaration==============
struct adj
{
  int to,dist;
  adj (int to=0,LL dist=0):to(to),dist(dist){}
  bool operator <(const adj &rhs) const
  {
    return dist>rhs.dist;
  }
};
//==============var declaration=================
const int MAXN=10010;
int n,m,s,e,v;
LL Low=INF,High=0,Mid;
LL cost[MAXN],d[MAXN];
vector <adj> Edge[MAXN];
//==============function declaration============
bool check(LL Cost);
//==============main code=======================
int main()
{  
  string FileName="cost";//程序名 
  string FloderName="COGS";//文件夹名 
  freopen((FileName+".in").c_str(),"r",stdin);
  freopen((FileName+".out").c_str(),"w",stdout);
#ifdef DEBUG  
  system(("cp C:\\Users\\Administrator\\Desktop\\"+FloderName+"\\standard.cpp C:\\Users\\Administrator\\Desktop\\"+FloderName+"\\submit.txt").c_str());
  clock_t Start_Time=clock();
#endif    
  scanf("%d%d%d%d%d",&n,&m,&s,&e,&v);
  For(i,1,n) 
  {
    scanf("%lld",cost+i);
    Low=min(Low,cost[i]);
    High=max(High,cost[i]);
  }
  For(i,1,m)
  {
    int from,to;
    LL fuel;
    scanf("%d%d%lld",&from,&to,&fuel);
    Edge[from].push_back(adj(to,fuel));
    Edge[to].push_back(adj(from,fuel));
  }
  Low=max(Low,cost[s]);
  while (Low<High)
  {
    Mid=(Low+High)>>1;
    if (!check(Mid))
      Low=Mid+1;
    else
      High=Mid;
  }
  if (!check(High))
    printf("%d\n",-1);
  else
  printf("%d\n",(Low+High)/2);
#ifdef DEBUG  
  clock_t End_Time=clock();
  printf("\n\nTime Used: %.4lf Ms\n",double(End_Time-Start_Time)/CLOCKS_PER_SEC);
#endif    
  return 0;
}
//================fuction code====================
bool check(LL Cost)
{
  priority_queue <adj> Q;
  Q.push(adj(s,0));
  For(i,1,n)
    d[i]=INF;
  d[s]=0;
  while (!Q.empty())
  {
    adj now=Q.top();Q.pop();
    if (d[now.to]!=now.dist) continue;
    if (now.to==e) break;
    int siz=Edge[now.to].size()-1;
    For(i,0,siz)
    {
      adj &e=Edge[now.to][i];
      if (cost[e.to]>Cost) continue;
      if (d[e.to]>d[now.to]+e.dist)
      {
        d[e.to]=d[now.to]+e.dist;
        Q.push(adj(e.to,d[e.to]));
      }
    }
  }
  return d[e]<v;
}