concept Edge in category algorithms

This is an excerpt from Manning's book Classic Computer Science Problems in Java.
Listing 4.2 Graph.java
package chapter4; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.stream.Collectors; // V is the type of the vertices in the Graph // E is the type of the edges public abstract class Graph<V, E extends Edge> { private ArrayList<V> vertices = new ArrayList<>(); protected ArrayList<ArrayList<E>> edges = new ArrayList<>(); public Graph() { } public Graph(List<V> vertices) { this.vertices.addAll(vertices); for (V vertex : vertices) { edges.add(new ArrayList<>()); } }

This is an excerpt from Manning's book Classic Computer Science Problems in Python.
Let’s start work on the framework by defining the Edge class, which is the simplest machinery in our graph framework.
Listing 4.1. edge.py
from __future__ import annotations from dataclasses import dataclass @dataclass class Edge: u: int # the "from" vertex v: int # the "to" vertex def reversed(self) -> Edge: return Edge(self.v, self.u) def __str__(self) -> str: return f"{self.u} -> {self.v}" !@%STYLE%@! {"css":"{\"css\": \"font-weight: bold;\"}","target":"[[{\"line\":0,\"ch\":0},{\"line\":0,\"ch\":4}],[{\"line\":1,\"ch\":0},{\"line\":1,\"ch\":4}],[{\"line\":6,\"ch\":18},{\"line\":6,\"ch\":22}],[{\"line\":0,\"ch\":16},{\"line\":0,\"ch\":22}],[{\"line\":1,\"ch\":17},{\"line\":1,\"ch\":23}],[{\"line\":0,\"ch\":0},{\"line\":0,\"ch\":4}],[{\"line\":1,\"ch\":0},{\"line\":1,\"ch\":4}],[{\"line\":6,\"ch\":18},{\"line\":6,\"ch\":22}],[{\"line\":0,\"ch\":16},{\"line\":0,\"ch\":22}],[{\"line\":1,\"ch\":17},{\"line\":1,\"ch\":23}],[{\"line\":1,\"ch\":9},{\"line\":1,\"ch\":14}],[{\"line\":4,\"ch\":5},{\"line\":4,\"ch\":10}],[{\"line\":5,\"ch\":0},{\"line\":5,\"ch\":5}],[{\"line\":9,\"ch\":4},{\"line\":9,\"ch\":7}],[{\"line\":12,\"ch\":4},{\"line\":12,\"ch\":7}],[{\"line\":10,\"ch\":8},{\"line\":10,\"ch\":14}],[{\"line\":13,\"ch\":8},{\"line\":13,\"ch\":14}],[{\"line\":9,\"ch\":4},{\"line\":9,\"ch\":7}],[{\"line\":12,\"ch\":4},{\"line\":12,\"ch\":7}],[{\"line\":13,\"ch\":8},{\"line\":13,\"ch\":38}]]"} !@%STYLE%@!An Edge is defined as a connection between two vertices, each of which is represented by an integer index. By convention, u is used to refer to the first vertex, and v is used to represent the second vertex. You can also think of u as “from” and v as “to.” In this chapter, we are only working with undirected graphs (graphs with edges that allow travel in both directions), but in directed graphs, also known as digraphs, edges can also be one-way. The reversed() method is meant to return an Edge that travels in the opposite direction of the edge it is applied to.
Now that we have concrete implementations of Edge and Graph, we can create a representation of the potential Hyperloop network. The vertices and edges in city_graph correspond to the vertices and edges represented in figure 4.2. Using generics, we can specify that vertices will be of type str (Graph[str]). In other words, the str type fills in for the type variable V.