- , new PriorityQueue(...)
- - . O(n)
, , .
PriorityQueue<edge> pr = new PriorityQueue<edge>(ar, comp) {
PriorityQueue(List<edge> ar, Comparator<edge> c) {
this(c);
for(int i = 0; i < queue.length; i++) {
queue[i] = ar.get(i);
}
this.size = queue.length;
heapify();
}
}
, PriorityQueue, .
- -, , . O(n)
, - heapify
.
edge
Comparable<edge>
. PriorityQueue<edge> pr = new PriorityQueue(ar);
edge implements Comparable<edge>
, :
class EdgeContainer implements Comparable<EdgeContainer> {
private static final Comparator<edge> comp = ;
private final edge edge;
EdgeContainer(Edge edge) { this.edge = edge; }
public int compareTo(EdgeContainer e) { return comp.compare(edge, e.edge); }
public edge getEdge() { return edge; }
}
List <EdgeContainer>ar=new ArrayList<>();
for(int i=0;i<e;i++)
{
int u=ss.nextInt();
int v=ss.nextInt();
int w=ss.nextInt();
ar.add(new EdgeContainer(new edge(u,v,w)));
}
PriorityQueue<EdgeContainer> qr = new PriorityQueue(ar);