Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <queue>
- #include <iostream>
- #include <vector>
- #include <cstring>
- #include <iostream>
- #include <bits/stdc++.h>
- using namespace std;
- struct node{
- int indx;
- double dis;
- node()
- {
- }
- node(int indx1, double dis1)
- {
- indx=indx1;
- dis=dis1;
- }
- bool operator < (const node &tmp) const{
- return dis>tmp.dis;
- }
- };
- int main()
- {
- int n;
- cin>>n;
- vector < pair<int,int> > v;
- int x,y;
- for(int i=0;i<n;i++)
- {
- cin>>x>>y;
- v.push_back(make_pair(x,y));
- }
- vector < pair<int, double> > g[n];
- vector<bool> visited(n,false);
- vector<double> dis(n,2e9);
- for(int i=0;i<n;i++)
- {
- for(int j=i;j<n;j++)
- {
- double d=sqrt(((v[j].first-v[i].first) * (v[j].first-v[i].first))+((v[j].second-v[i].second)*(v[j].second-v[i].second)));
- if(d<=10)
- g[i].push_back(make_pair(j,d));
- }
- }
- dis[0]=0;
- priority_queue<node> pq;
- pq.push(node(0,0));
- while(!pq.empty())
- {
- node c=pq.top();
- pq.pop();
- if(visited[c.indx])
- {
- continue;
- }
- visited[c.indx]=true;
- for(int i=0;i<g[c.indx].size();i++)
- {
- int s=g[c.indx][i].first;
- double t=g[c.indx][i].second;
- if(!visited[s] && c.dis+t<dis[s])
- {
- pq.push(node(s,c.dis+t));
- dis[s]=c.dis+t;
- }
- }
- }
- cout<<dis[n-1]<<endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement