Advanced
Graph Traversal Optimization
Optimize a pathfinding algorithm for a graph with negative weights and specific constraints.
📝 Conteúdo do Prompt
You are given a directed graph representing a flight network where edges have costs (which can be negative due to promotional subsidies) but no negative cycles. Design an algorithm that finds the cheapest path from a source node to all other nodes with exactly K stops. Analyze the time complexity of your solution and modify the standard Bellman-Ford algorithm to accommodate the strict 'K stops' constraint efficiently. Provide the pseudocode and a brief explanation of how you handle state management during traversal.