We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
For python code, at the begining I had a lot of test cases with time limit. I did a lot of tweaking and solved most of them.
However, I could not pass test case 2. I changed the way I read input, as a result the prblem was solved.
if name == 'main':
# Read all input at once using sys.stdin.read()
input_data = sys.stdin.read().splitlines()
# Process the first line to extract n and m
n, m = map(int, input_data[0].split())
# Initialize an empty list for edges
edges = []
# Process each of the next m lines to extract edges
for i in range(1, m + 1):
edges.append(list(map(int, input_data[i].split())))
# Process the second to last line to extract A and B
A, B = map(int, input_data[m + 1].split())
# Call the function with the parsed data
result = beautifulPath(n, edges, A, B)
# Write the result to the output file
with open(os.environ['OUTPUT_PATH'], 'w') as fptr:
fptr.write(str(result) + '\n')
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Minimum Penalty Path
You are viewing a single comment's thread. Return to all comments →
For python code, at the begining I had a lot of test cases with time limit. I did a lot of tweaking and solved most of them. However, I could not pass test case 2. I changed the way I read input, as a result the prblem was solved.
if name == 'main': # Read all input at once using sys.stdin.read() input_data = sys.stdin.read().splitlines()