← 返回 ramp 的题目列表URL Maze: Find Exit with BFS (Handle HTTP Status Codes and Keys)
类型:online_judge
Problem: URL Maze — Find the Exit via HTTP Calls
You are given a starting URL. By repeatedly sending HTTP GET requests to different URLs, you must navigate a “maze” and find an exit.
Part 1: Find the Exit (Basic)
Start from the given start URL and send an HTTP GET request.
Each URL response (assume JSON) provides a list of next URLs to visit (e.g., a neighbors/links field).
The URLs form a graph; you must search it to find a URL that satisfies the “exit condition” (e.g., a specific field in the response or a final result).
Use BFS (Breadth-First Search) and avoid revisiting the same URL.
Part 2: Robust Handling (Advanced)
Extend Part 1 to handle non-200 status codes:
503 Service Unavailable: retry the request (optionally with backoff or a fixed retry limit).
401 Unauthorized: you must use a captured key to construct request headers and retry/continue.
Key & Authorization
Some responses contain a key (or similar).
Store the key and use it to build headers (e.g., Authorization or a custom header) for subsequent requests.
Output
Print the exit information (e.g., exit URL, final key/flag, or the result field from the exit response).
Constraints / Notes
The number of URLs may be large; avoid infinite loops by tracking visited URLs.
Handle network errors and unexpected responses to keep the program robust.
Logging is allowed, but avoid excessive debug prints that obscure important signals.
Example
Input
https://example.com/start
Output
<exit_url_or_flag>