<>();edges = new ArrayList<>();}}public static class Edge {public int weight;public Node from;public Node to;public Edge(int weight, Node from, Node to) {this.weight = weight;this.from = from;this.to = to;}}public static void main(String[] args) {Scanner in = new Scanner(System.in);int n = in.nextInt();int m = in.nextInt();Graph graph = new Graph(n);for (int i = 0; i < m; i++) {int from = in.nextInt();int to = in.nextInt();int weight = in.nextInt();if (!graph.nodes.containsKey(from)) {graph.nodes.put(from, new Node(from));}if (!graph.nodes.containsKey(to)) {graph.nodes.put(to, new Node(to));}Node fromNode = graph.nodes.get(from);Node toNode = graph.nodes.get(to);Edge fromToEdge = new Edge(weight, fromNode, toNode);Edge toFromEdge = new Edge(weight, toNode, fromNode);fromNode.nexts.add(toNode);fromNode.out++;fromNode.in++;toNode.out++;toNode.in++;fromNode.edges.add(fromToEdge);toNode.edges.add(toFromEdge);graph.edges.add(fromToEdge);graph.edges.add(toFromEdge);}Set
参考资料算法和数据结构体系班-左程云
经验总结扩展阅读
- 11 微服务架构学习与思考:开源 API 网关02-以 Java 为基础的 API 网关详细介绍
- MasaFramework -- 缓存入门与设计
- 总是以自我为中心 从不与人交心的四大星座
- 天生就是公主命 修养与才华共存的星座女
- 2023年材料科学与工程专业大学排名及录取分数线
- 自律成为习惯 这四大星座显得与众不同
- 海信与创维电视哪个好 安全才是的选择
- 男生易经与论语中取名 易经起名大全
- 创造与魔法2022年最新礼包兑换码
- 液晶电视哪个牌子质量好 康佳与海信哪个质量好