public class City { String name; int id; static int idCounter = 0; public City(String name) { this.name=name; id = idCounter++; } } import java.util.ArrayList; public class Graph { public static void main(String[] args) { // TODO Auto-generated metho…