一.最短路径的简介

1.目标:给定一个边赋权有向图,找出从s到t的最短路径。

2.加权有向边的实现以及加权有向图(bag构成的数组,每一个bag中存从该点指出的边)的实现:

package com.cx.graph;

public class DirectedEdge {
    private final int v,w;
    private final double weight;
    
    public DirectedEdge(int v,int w,double weight) {
        //有向边的起点,终点和权重
        this.v=v;
        this.w=w;
        this.weight=weight;
    }
    public int from() {
        return v;
    }
    public int to() {
        return w;
    }
    public double weight() {
        return weight;
    }
    
}
View Code

相关文章:

猜你喜欢
  • 2021-08-13
  • 2021-09-26
  • 2021-10-16
  • 2021-07-07
相关资源
相似解决方案