Language: C++

import java.util.*;
import java.lang.*;
import java.io.*;
class Pair<E extends Comparable<E>,F extends Comparable<F>> implements Comparable<Pair<E,F>>{
    E first;
    F second;
    public Pair(E first, F second){
        this.first=first;
        this.second=second;
    }
    public E getFirst(){return first;}
    public F getSecond(){return second;}
    public String toString(){
        return "<"+first.toString()+","+second.toString()+">";
    }
    public int hashCode(){
        return first.hashCode()*30011+second.hashCode()+2;
    }
    public boolean equals(Object obj) {
        if (this == obj)
            return true;
        if (obj == null)
            return false;
        if (getClass() != obj.getClass())
            return false;
        Pair another = (Pair) obj;
        return this.getFirst().equals(another.getFirst())&&this.getSecond().equals(another.getSecond());
    }
    
    public int compareTo(Pair<E,F> another){
        if(this.getFirst().equals(another.getFirst())){
        	return this.getSecond().compareTo(another.getSecond());
        }
        return this.getFirst().compareTo(another.getFirst());
    }
    
}
class Edge implements Comparable<Edge>{
    Node end;
    double weight;
    public Edge(Node end, double weight){
        this.end = end;
        this.weight = weight;
    }
    public Edge(Node end){
        this.end = end;
        this.weight = 1;
    }
    public double getWeight(){
        return weight;
    }
    public Node getEnd(){
        return end;
    }
    public int compareTo(Edge another){
        if(this.getWeight()==another.getWeight()) return this.getEnd().compareTo(another.getEnd());
        else return (new Double(this.getWeight())).compareTo(new Double(another.getWeight()));
    }
    public String toString(){
        return "->"+end.toString()+"["+weight+"]";
    }
}
class Node implements Comparable<Node>{
    int id;
    List<Edge> edges;
    public Node(int id){
        this.id = id;
        this.edges = new LinkedList<>();
    }
    public void addEdge(Edge e){
        edges.add(e);
    }
    public void addEdge(Node n, double weight){
        this.addEdge(new Edge(n,weight));
    }
    public void addEdge(Node n){
        this.addEdge(n,1);
    }
    public void connect(Node n, double weight){
        edges.add(new Edge(n,weight));
    }
    public void connect(Node n){
        edges.add(new Edge(n));
    }
    public int getID(){
        return id;
    }
    public List<Edge> getEdges(){
        return edges;
    }
    public List<Node> getNeighbors(){
        LinkedList<Node> neighbors = new LinkedList<>();
        for(Edge e:this.getEdges()){
        	neighbors.add(e.getEnd());
        }
        return neighbors;
    }
    public int compareTo(Node another){
        return this.getID()-another.getID();
    }
    public String toString(){
        return "N"+id;
    }
}
class Graph{
    int size;
    List<Node> nodes;//nodes[i] have ID "i"
    public Graph(int size){
        this.size = size;
        nodes = new ArrayList<>(size);
        for(int i=0;i<size;i++){
        	nodes.add(new Node(i));
        }
    }
    public void addNode(){
        nodes.add(new Node(size));
        size++;
    }
    public void addDirectionalEdge(int i, int j, double w){ // i->j
        if(i>=size || j>=size)return;
        nodes.get(i).addEdge(nodes.get(j),w);
    }
    public void addDirectionalEdge(int i, int j){ // i->j
        if(i>=size || j>=size)return;
        nodes.get(i).addEdge(nodes.get(j));
    }
    public void addEdge(int i, int j, double w){
        addDirectionalEdge(i,j,w);
        addDirectionalEdge(j,i,w);
    }
    public void addEdge(int i, int j){
        addDirectionalEdge(i,j);
        addDirectionalEdge(j,i);
    }
    public int getSize(){
        return size;
    }
    public List<Edge> getEdges(int i){
        return nodes.get(i).getEdges();
    }
    public List<Node> getNeighbors(int i){
        return nodes.get(i).getNeighbors();
    }
    public double getDistance(int i, int j){
        double ans = Double.POSITIVE_INFINITY;
        for(Edge e:this.getEdges(i)){
        	if(e.getEnd().getID()==j) ans = Math.min(ans,e.getWeight());
        }
        return ans;
    }
    public double pathDistance(int[] nodes){
        double ans = 0;
        for(int n=1;n<nodes.length;n++){
        	ans += this.getDistance(nodes[n-1],nodes[n]);
        }
        return ans;
    }
    public double pathDistance(Integer[] nodes){
        double ans = 0;
        for(int n=1;n<nodes.length;n++){
        	ans += this.getDistance(nodes[n-1],nodes[n]);
        }
        return ans;
    }
    public double pathDistance(List<Integer> nodes){
        return pathDistance(nodes.toArray(new Integer[0]));
    }
    public List<Integer> dijkstra(int start, int end){
        double[] distance = new double[size];
        for(int n=0;n<size;n++) distance[n]=Double.POSITIVE_INFINITY;
        distance[start]=0;
        int[] prev = new int[size];
        for(int n=0;n<size;n++) prev[n]=-1;
        
        PriorityQueue<Pair<Double,Integer>> A = new PriorityQueue<>();
        A.add(new Pair<>(distance[start],start));
        while(A.size()>0){
        	Pair<Double, Integer> p = A.poll();
            int u = p.getSecond();
            if(distance[u] < p.getFirst()) continue;
        	for(Node nodeV :getNeighbors(u)){
        	    int v = nodeV.getID();
        	    double newDistance = distance[u] + getDistance(u,v);
        	    if(distance[v]>newDistance){
        	        A.remove(new Pair<>(distance[v],v));
        	        distance[v] = newDistance;
        	        prev[v] = u;
        	        A.add(new Pair<>(distance[v],v));
        	    }
        	}
        }
        LinkedList<Integer> ans = new LinkedList<>();
        ans.push(end);
        int cur = end;
        while(cur!=start){
        	ans.push(prev[cur]);
        	cur = prev[cur];
        }
        return ans;
    }
    
    
}


class Barrier{
    double x,y,r;
    public Barrier(double x, double y, double r){
        this.x=x;
        this.y=y;
        this.r=r;
    }
    public double distance(Barrier another){
        double d = Math.sqrt((this.x-another.x)*(this.x-another.x) + (this.y-another.y)*(this.y-another.y));
        return Math.max(0,d-this.r-another.r);
    }
}
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        double startX = sc.nextDouble();
        double startY = sc.nextDouble();
        double endX = sc.nextDouble();
        double endY = sc.nextDouble();
        int N = sc.nextInt();
        Barrier[] barrier = new Barrier[N+2];
        barrier[0] = new Barrier(startX,startY,0);
        barrier[1] = new Barrier(endX,endY,0);
        for(int n=2;n<N+2;n++){
        	double x = sc.nextDouble();
        	double y = sc.nextDouble();
        	double r = sc.nextDouble();
        	barrier[n] = new Barrier(x,y,r);
        }
        Graph graph = new Graph(N+2);
        for(int i=0;i<N+1;i++)for(int j=i+1;j<=N+1;j++){
        	graph.addEdge(i,j,barrier[i].distance(barrier[j]));
        }
        System.out.println(graph.pathDistance(graph.dijkstra(0,1)));
    }
}


Compiler output:
a.cc:1:1: error: 'import' does not name a type
    1 | import java.util.*;
      | ^~~~~~
a.cc:1:1: note: C++20 'import' only available with '-fmodules-ts'
a.cc:2:1: error: 'import' does not name a type
    2 | import java.lang.*;
      | ^~~~~~
a.cc:2:1: note: C++20 'import' only available with '-fmodules-ts'
a.cc:3:1: error: 'import' does not name a type
    3 | import java.io.*;
      | ^~~~~~
a.cc:3:1: note: C++20 'import' only available with '-fmodules-ts'
a.cc:4:7: error: 'Pair' is not a class template
    4 | class Pair<E extends Comparable<E>,F extends Comparable<F>> implements Comparable<Pair<E,F>>{
      |       ^~~~
a.cc:4:12: error: 'E' was not declared in this scope
    4 | class Pair<E extends Comparable<E>,F extends Comparable<F>> implements Comparable<Pair<E,F>>{
      |            ^
a.cc:4:72: error: expected initializer before 'Comparable'
    4 | class Pair<E extends Comparable<E>,F extends Comparable<F>> implements Comparable<Pair<E,F>>{
      |                                                                        ^~~~~~~~~~
a.cc:38:23: error: expected initializer before 'Comparable'
   38 | class Edge implements Comparable<Edge>{
      |                       ^~~~~~~~~~
a.cc:63:23: error: expected initializer before 'Comparable'
   63 | class Node implements Comparable<Node>{
      |                       ^~~~~~~~~~
a.cc:107:5: error: 'List' does not name a type
  107 |     List<Node> nodes;//nodes[i] have ID "i"
      |     ^~~~
a.cc:108:11: error: expected ':' before 'Graph'
  108 |     public Graph(int size){
      |           ^~~~~~
      |           :
a.cc:115:11: error: expected ':' before 'void'
  115 |     public void addNode(){
      |           ^~~~~
      |           :
a.cc:119:11: error: expected ':' before 'void'
  119 |     public void addDirectionalEdge(int i, int j, double w){ // i->j
      |           ^~~~~
      |           :
a.cc:123:11: error: expected ':' before 'void'
  123 |     public void addDirectionalEdge(int i, int j){ // i->j
      |           ^~~~~
      |           :
a.cc:127:11: error: expected ':' before 'void'
  127 |     public void addEdge(int i, int j, double w){
      |           ^~~~~
      |           :
a.cc:131:11: error: expected ':' before 'void'
  131 |     public void addEdge(int i, int j){
      |           ^~~~~
      |           :
a.cc:135:11: error: expected ':' before 'int'
  135 |     public int getSize(){
      |           ^~~~
      |           :
a.cc:138:11: error: expected ':' before 'List'
  138 |     public List<Edge> getEdges(int i){
      |           ^~~~~
      |           :
a.cc:138:12: error: 'List' does not name a type
  138 |     public List<Edge> getEdges(int i){
      |            ^~~~
a.cc:141:11: error: expected ':' before 'List'
  141 |     public List<Node> getNeighbors(int i){
      |           ^~~~~
      |           :
a.cc:141:12: error: 'List' does not name a type
  141 |     public List<Node> getNeighbors(int i){
      |            ^~~~
a.cc:144:11: error: expected ':' before 'double'
  144 |     public double getDistance(int i, int j){
      |           ^~~~~~~
      |           :
a.cc:151:11: error: expected ':' before 'double'
  151 |     public double pathDistance(int[] nodes){
      |           ^~~~~~~
      |           :
a.cc:151:38: error: expected ',' or '...' before 'nodes'
  151 |     public double pathDistance(int[] nodes){
      |                                      ^~~~~
a.cc:158:11: error: expected ':' before 'double'
  158 |     public double pathDistance(Integer[] nodes){
      |           ^~~~~~~
      |           :
a.cc:158:32: error: 'Integer' has not been declared
  158 |     public double pathDistance(Integer[] nodes){
      |                                ^~~~~~~
a.cc:158:42: error: expected ',' or '...' before 'nodes'
  158 |     public double pathDistance(Integer[] nodes){
      |                                          ^~~~~
a.cc:158:19: error: 'double Graph::pathDistance(int*)' cannot be overloaded with 'double Graph::pathDistance(int*)'
  158 |     public double pathDistance(Integer[] nodes){
      |                   ^~~~~~~~~~~~
a.cc:151:19: note: previous declaration 'double Graph::pathDistance(int*)'
  151 |     public double pathDistance(int[] nodes){
      |                   ^~~~~~~~~~~~
a.cc:165:11: error: expected ':' before 'double'
  165 |     public double pathDistance(List<Integer> nodes){
      |           ^~~~~~~
      |           :
a.cc:165:32: error: 'List' has not been declared
  165 |     public double pathDistance(List<Integer> nodes){
      |                                ^~~~
a.cc:165:36: error: expected ',' or '...' before '<' token
  165 |     public double pathDistance(List<Integer> nodes){
      |                                    ^
a.cc:168:11: error: expected ':' before 'List'
  168 |     public List<Integer> dijkstra(int start, int end){
      |           ^~~~~
      |           :
a.cc:168:12: error: 'List' does not name a type
  168 |     public List<Integer> dijkstra(int start, int end){
      |            ^~~~
a.cc:203:2: error: expected ';' after class definition
  203 | }
      |  ^
      |  ;
a.cc: In constructor 'Graph::Graph(int)':
a.cc:109:14: error: request for member 'size' in '(Graph*)this', which is of pointer type 'Graph*' (maybe you meant to use '->' ?)
  109 |         this.size = size;
      |              ^~~~
a.cc:110:9: error: 'nodes' was not declared in this scope
  110 |         nodes = new ArrayList<>(size);
      |         ^~~~~
a.cc:110:21: error: 'ArrayList' does not name a type
  110 |         nodes = new ArrayList<>(size);
      |                     ^~~~~~~~~
a.cc:110:31: error: expected primary-expression before '>' token
  110 |         nodes = new ArrayList<>(size);
      |                               ^
a.cc:112:37: error: invalid use of incomplete type 'class Node'
  112 |                 nodes.add(new Node(i));
      |                                     ^
a.cc:63:7: note: forward declaration of 'class Node'
   63 | class Node implements Comparable<Node>{
      |       ^~~~
a.cc: In member function 'void Graph::addNode()':
a.cc:116:9: error: 'nodes' was not declared in this scope
  116 |         nodes.add(new Node(size));
      |         ^~~~~
a.cc:116:32: error: invalid use of incomplete type 'class Node'
  116 |         nodes.add(new Node(size));
      |                                ^
a.cc:63:7: note: forward declaration of 'class Node'
   63 | class Node implements Comparable<Node>{
      |       ^~~~
a.cc: In member function 'void Graph::addDirectionalEdge(int, int, double)':
a.cc:121:9: error: 'nodes' was not declared in this scope
  121 |         nodes.get(i).addEdge(nodes.get(j),w);
      |         ^~~~~
a.cc: In member function 'void Graph::addDirectionalEdge(int, int)':
a.cc:125:9: error: 'nodes' was not declared in this scope
  125 |         nodes.get(i).addEdge(nodes.get(j));
      |         ^~~~~
a.cc: In member function 'double Graph::getDistance(int, int)':
a.cc:145:22: error: 'Double' was not declared in this scope; did you mean 'double'?
  145 |         double ans = Double.POSITIVE_INFINITY;
      |                      ^~~~~~
      |                      double
a.cc:146:18: error: variable 'Edge e' has initializer but incomplete type
  146 |         for(Edge e:this.getEdges(i)){
      |                  ^
a.cc:146:25: error: request for member 'getEdges' in '(Graph*)this', which is of pointer type 'Graph*' (maybe you meant to use '->' ?)
  146 |         for(Edge e:this.getEdges(i)){
      |                         ^~~~~~~~
a.cc:147:49: error: 'Math' was not declared in this scope
  147 |                 if(e.getEnd().getID()==j) ans = Math.min(ans,e.getWeight());
      |                                                 ^~~~
a.cc: In member function 'double Graph::pathDistance(int*)':
a.cc:153:23: error: 'nodes' was not declared in this scope
  153 |         for(int n=1;n<nodes.length;n++){
      |                       ^~~~~
a.cc:154:29: error: request for member 'getDistance' in '(Graph*)this', which is of pointer type 'Graph*' (maybe you meant to use '->' ?)
  154 |                 ans += this.getDistance(nodes[n-1],nodes[n]);
      |                             ^~~~~~~~~~~
a.cc: In member function 'double Graph::pathDistance(int*)':
a.cc:160:23: error: 'nodes' was not declared in this scope
  160 |         for(int n=1;n<nodes.length;n++){
      |                       ^~~~~
a.cc:161:29: error: request for member 'getDistance' in '(Graph*)this', which is of pointer type 'Graph*' (maybe you meant to use '->' ?)
  161 |                 ans += this.getDistance(nodes[n-1],nodes[n]);
      |                             ^~~~~~~~~~~
a.cc: In member function 'double Graph::pathDistance(int)':
a.cc:166:29: error: 'nodes' was not declared in this scope
  166 |         return pathDistance(nodes.toArray(new Integer[0]));
      |                             ^~~~~
a.cc:166:47: error: 'Integer' does not name a type
  166 |         return pathDistance(nodes.toArray(new Integer[0]));
      |                                               ^~~~~~~
a.cc: At global scope:
a.cc:208:11: error: expected ':' before 'Barrier'
  208 |     public Barrier(double x, double y, double r){
      |           ^~~~~~~~
      |           :
a.cc:213:11: error: expected ':' before 'double'
  213 |     public double distance(Barrier another){
      |           ^~~~~~~
      |           :
a.cc:217:2: error: expected ';' after class definition
  217 | }
      |  ^
      |  ;
a.cc: In constructor 'Barrier::Barrier(double, double, double)':
a.cc:209:14: error: request for member 'x' in '(Barrier*)this', which is of pointer type 'Barrier*' (maybe you meant to use '->' ?)
  209 |         this.x=x;
      |              ^
a.cc:210:14: error: request for member 'y' in '(Barrier*)this', which is of pointer type 'Barrier*' (maybe you meant to use '->' ?)
  210 |         this.y=y;
      |              ^
a.cc:211:14: error: request for member 'r' in '(Barrier*)this', which is of pointer type 'Barrier*' (maybe you meant to use '->' ?)
  211 |         this.r=r;
      |              ^
a.cc: In member function 'double Barrier::distance(Barrier)':
a.cc:214:20: error: 'Math' was not declared in