Floyd : City of Blinding Lights

  • + 0 comments

    If you want a better framework to start from so you can just start coding, here is a better starting point for Python 3 in the usual Hackerrank style:

    #!/bin/python3
    
    import math
    import os
    import random
    import re
    import sys
    
    #
    # Complete the 'floyd' function below.
    #
    # The function is expected to return an INTEGER_ARRAY.
    # The function accepts following parameters:
    #  1. INTEGER n the number of nodes
    #  2. INTEGER m the number of edges
    #  3. INT ARRAY starts, the starting point of an edge 
    #  4. INT ARRAY ends, the ending point of an edge
    #  5. INT ARRAY costs, the cost of an edge 
    #  6. LIST of TUPLES queries, where each tuple is (start, end)
    #
    
    def floyd(n, m, starts, ends, costs, queries):
        #Write your code here
    
    if __name__ == '__main__':
        road_nodes, road_edges = map(int, input().rstrip().split())
    
        road_from = [0] * road_edges
        road_to = [0] * road_edges
        road_weight = [0] * road_edges
    
        for i in range(road_edges):
            road_from[i], road_to[i], road_weight[i] = map(int, input().rstrip().split())
    
        q = int(input().strip())
    
        queries = []
        
        for q_itr in range(q):
            first_multiple_input = input().rstrip().split()
    
            x = int(first_multiple_input[0])
    
            y = int(first_multiple_input[1])
            
            queries.append([x, y])
            
        answers = floyd(road_nodes, road_edges, road_from, road_to, road_weight, queries)
        
        for ans in answers:
            print(ans)