← 返回 ramp 的题目列表Find the Exit in a URL Maze with HTTP Error Handling
类型:online_judge
Problem: Find the Exit in a URL Maze with HTTP Error Handling
You are given a starting URL. Each URL represents a room in a maze. Fetching a URL returns:
an HTTP status code;
whether this room is an exit;
a list of neighboring URLs reachable from this room.
Starting from the given URL, find any reachable exit URL. If multiple exits exist, return the one found first by BFS, meaning the exit with the minimum number of links from the start. Within the same BFS layer, visit neighbors in the input order.
You must handle HTTP errors:
2xx: success; parse and expand this room;
4xx: client error; treat this URL as a dead end and do not retry;
5xx: server error; retry up to max_retries additional times. If it still returns 5xx, treat this URL as temporarily unreachable and do not expand it;
Avoid visiting the same URL repeatedly because the maze may contain cycles.
Input Format
For local testing, stdin simulates the HTTP service.
First line:
n start_url max_retries
n: number of URLs;
start_url: starting URL;
max_retries: maximum number of extra retries after an initial 5xx response for each URL.
The next n lines each describe one URL:
url is_exit status_sequence k neighbor1 neighbor2 ... neighbork
url: URL name without spaces;
is_exit: 1 if this URL is an exit, otherwise 0;
status_sequence: comma-separated HTTP status codes returned by consecutive fetches to this URL. If the URL is fetched more times than the sequence length, the last status code is repeated;
k: number of neighbors;
followed by k neighboring URLs.
Output Format
If an exit is found, print its URL;
Otherwise print:
NOT_FOUND
Constraints
1 <= n <= 10^5
Total URL length is at most 10^6
Number of edges is at most 2 * 10^5
0 <= max_retries <= 5
Example
Input:
4 A 2
A 0 200 2 B C
B 0 200 1 D
C 0 404 0
D 1 200 0
Output:
D
Example
Input
4 A 2
A 0 200 2 B C
B 0 200 1 D
C 0 404 0
D 1 200 0
Output
D