Cloudy Days
Practice
3.1 (7 votes)
Breadth First search
Graphs
Algorithms
Problem
66% Success 2881 Attempts 20 Points 1s Time Limit 256MB Memory 1024 KB Max Code
Alice is navigating the country of Cloudland on a cloudy day, making it challenging to see her way. She has a car with \(K\) units of fuel remaining, where each unit of fuel allows her to travel a distance of \(1\) unit.
Given the country's layout, consisting of several interconnected cities, and her current location, your task is to determine and print the total possible number of cities she can visit reach if she exhausts all her fuel.
Input Format:
- The input starts with three integers:
- \(N\): The number of cities in Cloudland.
- \(M \): The number of roads connecting differenct cities in Cloudland
- \(K\): The remaining fuel units in Alice's car.
- \(C\) : Alice's current city
- The following \(M\) lines describe the road connections between cities as pairs of integers \(u,v\), indicating a bidirectional road between cities \(u\) and \(v\)
Output Format:
Output a single integer representing the total possible number of cities Alice can reach if she uses up all \(K\) units of her fuel.
Constraints:
\(2 \leq N \leq 10^3 \\ 0 \leq M \leq (N*(N-1))/2 \\ 1 \leq K \leq 10^6 \\ 1 \leq C \leq N\)
Submissions
Please login to view your submissions
Similar Problems
Points:20
91 votes
Tags:
AlgorithmsBreadth First SearchEasyGraphs
Points:20
15 votes
Tags:
AlgorithmsBreadth First SearchGraphsLogic-Based
Points:20
184 votes
Tags:
Breadth First SearchEasyGraphsOpen
Editorial