fork download
  1. #include <iostream>
  2. #include <iomanip>
  3. #include <cmath>
  4. #include <algorithm>
  5. #include <vector>
  6. #include <queue>
  7. using namespace std;
  8.  
  9. const int inf = 10000000;
  10.  
  11. struct node {
  12. int x;
  13. int y;
  14. };
  15.  
  16. vector <node> cities;
  17. int d [200];
  18. void diikstra ( int n ){
  19. d[0] = 0;
  20. for (int i = 1; i < n; i++){
  21. d[i] = inf;
  22. }
  23. priority_queue < pair <int, int> > q;
  24. q.push({d[0], 0});
  25. while (!q.empty()) {
  26. int num_v = q.top().second;
  27. node cur = cities[num_v];
  28. int distv = -q.top().first;
  29. q.pop();
  30. for (int i = 0; i < n; i++) {
  31. int distance = max (distv, (cur.x - cities[i].x)*(cur.x - cities[i].x)+(cur.y - cities[i].y)*(cur.y - cities[i].y));
  32. if(d[i] > distance){
  33. d[i] = distance;
  34. q.push ({-distance, i});
  35. }
  36. }
  37. }
  38. }
  39. int main() {
  40. cout.precision(3);
  41. int q;
  42. cin >> q;
  43. for (int w = 0; w < q; w++){
  44. int n;
  45. cin >> n;
  46. for (int i = 0; i < n; i++){
  47. int a, b;
  48. cin >> a >> b;
  49. cities.push_back({a,b});
  50. }
  51. diikstra (n);
  52. for (int i = 0; i < n; i++){
  53. cities.pop_back();
  54. }
  55. cout << fixed << sqrt(d[1]) << endl;
  56.  
  57.  
  58. }
  59. return 0;
  60. }
Success #stdin #stdout 0s 4396KB
stdin
1 3
8 9
0 1
14 14
stdout
11.314