Lekcja – Graf skierowany z wagami

def add_node(V, node):

    if node in V.keys():
        return
    else:
        V[node] = {}


def add_edge(V, source, dest, weight):

    if not source in V.keys() or not dest in V.keys():
        return
    else:
        if not dest in V[source].keys():
            V[source][dest] = weight

V = {}
add_node(V, 'DL')
add_node(V, 'D')
add_node(V, 'C')
add_node(V, 'E')
add_node(V, 'R')
add_node(V, 'B')
add_edge(V, 'DL', 'D', 100)
add_edge(V, 'DL', 'C', 1600)
add_edge(V, 'D', 'R', 0)
add_edge(V, 'C', 'E', 300)
add_edge(V, 'E', 'R', 0)
add_edge(V, 'E', 'C', 600)
add_edge(V, 'R', 'B', 150)
print(V)
print(V['C']['E'])

Lab

routes = {
    'RS' : { 'M' : 1.5, 'T' : 1, 'U' : 9 },
    'M'  : { 'U' : 1.5 },
    'T'  : { 'S' : 1},
    'S'  : { 'U' : 1} 
}

my_route = ['RS', 'T', 'S', 'U']

sum = 0
start = my_route[0]
for destination in my_route[1:]:
    sum += routes[start][destination]
    start = destination

print('The cost for 1 student is:', sum)

print('The cost for 3 students is:', 3*sum)



print('The cost for 3 students in taxi is:', routes['RS']['U'])