Please generate a unique JSON object suitable for automating the…
- User
Assistant: User: Please generate a unique JSON object suitable for automating the programming task testing platform, strictly in the following format: { "Title": "Task Name", "Task Description": "Description of the task.", "Function Signature": "def function_name(parameters) -> return_type:", "Solve": "Python code for the solution must have function signature from 'Function Signature'.", "Input": "Description of the input parameters.", "Output": "Description of the expected output.", "Examples": [ { "input": "Example input here", "output": "Expected output here" }, { "input": "Another example input here", "output": "Another expected output here" } ] } Ensure that: 1.The task includes graph traversal algorithms. 2.The JSON follows this exact structure and does not include any additional text or variations. 3.The task should be complex and unique, avoiding direct copying from common platforms like LeetCode or similar sources. 4.The solution must not use any imports in the code (i.e., no import statements). 5.The solution must contain only one function. 6.Ensure that the outputs are different each time, so no two consecutive outputs are the same. Assistant:
- Assistant
{ "Title": "Graph Shortest Path Calculation", "Task Description": "Implement a function that finds the shortest path from a start node to all other nodes in a weighted directed graph using Dijkstra's algorithm.", "Function Signature": "def dijkstra_shortest_path(n, edges, start) -> list:", "Solve": "def dijkstra_shortest_path(n, edges, start) -> list:\n # Initialize distances with infinity\n distances = [float('inf')] * n\n distances[start] = 0\n visited = [False] * n\n \n for _ in range(n):\n # Find the unvisited node with the smallest distance\n min_distance = float('inf')\n u = -1\n for i in range(n):\n if not visited[i] and distances[i] < min_distance:\n min_distance = distances[i]\n u = i\n \n if u == -1: # No nodes left to process\n break\n\n # Mark as visited\n visited[u] = True\n \n # Update distances for each neighbor v of u\n for v, weight in edges[u]:\n if not visited[v] and distances[u] + weight < distances[v]:\n distances[v] = distances[u] + weight\n\n return distances", "Input": "The function takes the following parameters: n (number of nodes), edges (list of edges where each edge is a tuple (u, v, w) representing a directed edge from u to v with weight w), and start (the starting node index, 0 <= start < n).", "Output": "A list of shortest distances from the start node to all other nodes. The distance to the start node itself is zero, and distances to unreachable nodes should be represented as infinity.", "Examples": [ { "input": "n = 5, edges = {0: [(1, 2), (2, 4)], 1: [(2, 1), (3, 7)], 2: [(3, 3)], 3: [(4, 1)], 4: []}, start = 0", "output": "[0, 2, 3, 6, 7]" }, { "input": "n = 4, edges = {0: [(1, 1)], 1: [(2, 2)], 2: [(3, 1)], 3: []}, start = 1", "output": "[inf, 0, 2, 3]" } ] }