Advertisement
MinhNGUYEN2k4

Untitled

Mar 21st, 2021
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.13 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #define float double
  3. #define fi first
  4. #define se second
  5. #define mp make_pair
  6. #define pb push_back
  7. #define Co_mot_su_that_la return
  8.  
  9. using namespace std;
  10. typedef pair<int ,float> ii;
  11. typedef pair<float, int> foi;
  12. typedef pair<int,ii> iii;
  13. typedef vector<int> vi;
  14. typedef vector<ii> vii;
  15. typedef vector<vi> vvi;
  16. typedef vector<iii> viii;
  17.  
  18. const int Minh_dep_trai = 0;
  19. const int N = 1005;
  20. const double EPS = 1e-6;
  21.  
  22. int q;
  23. int n;
  24. float w,m;
  25. bool mark[N][N];
  26. float a[N][N];
  27. pair<float,float> b[N];
  28. float d[N];
  29.  
  30. float sqr (const float &x)
  31. {
  32.     return x*x;
  33. }
  34.  
  35. float dis (pair<float,float> a, pair<float,float> b)
  36. {
  37.     return sqrt(sqr(a.fi-b.fi) + sqr(a.se-b.se));
  38. }
  39.  
  40. void dijkstra()
  41. {
  42.     priority_queue<foi, vector<foi>, greater<foi> > qu;
  43.     d[1] = 0;
  44.     qu.push(foi(0,1));
  45.     while (qu.size())
  46.     {
  47.         int u = qu.top().second;
  48.         double du = qu.top().first;
  49.         qu.pop();
  50.         if (du > d[u] + EPS) continue;
  51.         for(int v=1; v<=n; v++)
  52.         {
  53.             if (d[v] > du + a[u][v] + EPS)
  54.                 qu.push(foi(d[v] = du + a[u][v],v));
  55.         }
  56.     }
  57. }
  58.  
  59. signed main()
  60. {
  61.   ios_base::sync_with_stdio(false);
  62.   cin.tie(0);cout.tie(0);
  63.   freopen("test.inp","r",stdin);
  64.   q=1;
  65.   while (q--)
  66.   {
  67.     //your code goes here
  68.     cin >> n >> w;
  69.     cin >> m;
  70.     for(int i=1; i<=n; i++)
  71.     {
  72.         cin >> b[i].fi >> b[i].se;
  73.     }
  74.     for(int i=1; i<=(int)w; i++)
  75.     {
  76.         int u,v;
  77.         cin >> u >> v;
  78.         mark[u][v] = mark[v][u] = true;
  79.     }
  80.     for(int i=1; i<=n; i++)
  81.     {
  82.         a[i][i] = 999999;
  83.         for(int j=i+1; j<=n; j++)
  84.         {
  85.             if (mark[i][j]) continue;
  86.             float way = dis(b[i],b[j]);
  87.             if (way + EPS < m)
  88.             {
  89.                 a[i][j] = way;
  90.                 a[j][i] = way;
  91.             }
  92.             else{
  93.                 a[i][j] = 999999;
  94.                 a[j][i] = 999999;
  95.             }
  96.         }
  97.         d[i] = 999999;
  98.     }
  99.     dijkstra();
  100.     if (d[n] >= 999999) cout << -1;
  101.     else
  102.     cout << int(d[n]*1000);
  103.   }
  104.   Co_mot_su_that_la Minh_dep_trai;
  105. }
  106.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement