Language: C++

def solve():
    import sys
    from itertools import combinations
    from bisect import bisect
    from heapq import heappush, heappop
    file_input = sys.stdin
    inf = float('inf')
    while True:
        n, m, c, s, g = map(int, file_input.readline().split())
        if n == 0:
            break
        
        # Adjacency matrices recording distances for each company
        adj_matrices = [[[inf] * n for j in range(n)] for i in range(c)]
        
        for i in range(m):
            x, y, d, c = map(int, file_input.readline().split())
            mat = adj_matrices[c - 1]
            x -= 1
            y -= 1
            pre_d = mat[x][y]
            if d < pre_d:
                mat[x][y] = d
                mat[y][x] = d
        
        p = file_input.readline()
        
        stations = list(range(n))
        
        # Adjacency list for the Dijkstra's algorithm
        adj_list = [[] for i in range(n)]
        
        for mat in adj_matrices:
            q = list(map(int, file_input.readline().split()))
            r = list(map(int, file_input.readline().split()))
            
            # Warshall–Floyd Algorithm
            for k in range(n):
                sc = stations.copy()
                del sc[k]
                for x, y in combinations(sc, 2):
                    d = min(mat[x][y], mat[x][k] + mat[k][y])
                    mat[x][y] = d
                    mat[y][x] = d
                    
                    # Fare calculation
                    idx = bisect(q, d)
                    fare = 0
                    pre_sd = 0
                    for sd, f in zip(q[:idx], r):
                        fare += f * (sd - pre_sd)
                        pre_sd = sd
                    fare += r[idx] * (d - pre_sd)
                    adj_list[x].append((fare, y))
                    adj_list[y].append((fare, x))
        
        # Dijkstra's algorithm
        s -= 1
        g -= 1
        fare = [inf] * n
        fare[s] = 0
        pq = [(0, s)]
        while pq:
            u_fare, u = heappop(pq)
                    
            if u == g:
                print(u_fare)
                break
            
            for f, v in adj_list[u]:
                new_fare = u_fare + f
                if new_fare < fare[v]:
                    fare[v] = new_fare
                    heappush(pq, (new_fare, v))
        else:
            print(-1)

solve()


Compiler output:
a.cc:7:17: warning: multi-character character constant [-Wmultichar]
    7 |     inf = float('inf')
      |                 ^~~~~
a.cc:13:11: error: invalid preprocessing directive #Adjacency
   13 |         # Adjacency matrices recording distances for each company
      |           ^~~~~~~~~
a.cc:30:11: error: invalid preprocessing directive #Adjacency
   30 |         # Adjacency list for the Dijkstra's algorithm
      |           ^~~~~~~~~
a.cc:30:42: warning: missing terminating ' character
   30 |         # Adjacency list for the Dijkstra's algorithm
      |                                          ^
a.cc:37:15: error: extended character – is not valid in an identifier
   37 |             # Warshall–Floyd Algorithm
      |               ^
a.cc:37:15: error: invalid preprocessing directive #Warshall\U00002013Floyd
   37 |             # Warshall–Floyd Algorithm
      |               ^~~~~~~~~~~~~~
a.cc:46:23: error: invalid preprocessing directive #Fare
   46 |                     # Fare calculation
      |                       ^~~~
a.cc:57:11: error: invalid preprocessing directive #Dijkstra
   57 |         # Dijkstra's algorithm
      |           ^~~~~~~~
a.cc:57:19: warning: missing terminating ' character
   57 |         # Dijkstra's algorithm
      |                   ^
a.cc:1:1: error: 'def' does not name a type
    1 | def solve():
      | ^~~