记录编号 118081 评测结果 AAAAAAAAAAAAAAAAAAAA
题目名称 [USACO Oct08] 被破坏的电力系统 最终得分 100
用户昵称 GravatarHouJikan 是否通过 通过
代码语言 C++ 运行时间 0.230 s
提交时间 2014-09-03 21:29:48 内存使用 0.34 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=0x7ffffff;
//==============struct declaration==============
struct node
{
  int to;
  double dist;
  node (int to=0,double dist=0):to(to),dist(dist){}
  bool operator <(const node& rhs) const
  {
    return dist>rhs.dist;
  }
};
struct points
{
  int x,y;
}point[1010];
struct adj
{
  int from,to;
  double dist;
  adj(int from=0,int to=0,double dist=0):from(from),to(to),dist(dist){}
};
//==============var declaration=================
int n,w;
double m;
double dist[1010];
bool vis[1010];
vector <adj> Edge[1010];
//==============function declaration============
double dis(int i,int j);
void djstra();
//==============main code=======================
int main()
{  
  string FileName="pwrfail";//程序名 
  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%lf",&n,&w,&m);
  double d;
  For(i,1,n)
  {
    scanf("%d%d",&point[i].x,&point[i].y);
    For(j,1,i-1)
    {
      d=dis(i,j);
      if (d<m)
      {
        Edge[i].push_back(adj(i,j,d));
        Edge[j].push_back(adj(j,i,d));
      }
    }
  }
  For(i,1,w)
  {
    int s,e;
    scanf("%d%d",&s,&e);
    Edge[s].push_back(adj(s,e,0));
    Edge[e].push_back(adj(e,s,0));
  }
  djstra();
#ifdef DEBUG  
  clock_t End_Time=clock();
  cout<<endl<<endl<<"Time Used: "<<double(End_Time-Start_Time)/CLOCKS_PER_SEC<<endl;
#endif    
  return 0;
}
//================fuction code====================
double dis(int i,int j)
{
  LL xx=point[i].x-point[j].x;
  LL yy=point[i].y-point[j].y;
  return sqrt(double (xx*xx+yy*yy));
}
void djstra()
{
  memset(vis,0,sizeof(vis));
  For(i,1,n)
    dist[i]=INF;
  dist[1]=0;
  priority_queue <node> Q;
  Q.push(node(1,0));
  while (!Q.empty())
  {
    node now=Q.top();Q.pop();
    if (vis[now.to]) continue;
    vis[now.to]=true;
    int siz=Edge[now.to].size()-1;
    For(i,0,siz)
    {
      adj &e=Edge[now.to][i];
      if (!vis[e.to])
        if (dist[e.to]>dist[now.to]+e.dist)
        {
          dist[e.to]=dist[now.to]+e.dist;
          Q.push(node(e.to,dist[e.to]));
        }
    }
  }
  if (vis[n])
    printf("%d\n",int (dist[n]*1000));
  else
    pritnf("-1\n");
}