Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

please help me to solve this problem using graph theory in puthon . time limit per test: 2 secondso memory limit per test: 1024 megabytes

please help me to solve this problem using graph theory in puthon .
image text in transcribed
time limit per test: 2 secondso memory limit per test: 1024 megabytes input: standard input output: standard output Yi and Han are two swans living on a lake. They are good friends and often play together. One day they woke up and found out that because of the snow last night, they were separate in two different areas by ice. The lake can be viewed as a rc grid. We will use " X " to represent a cell of ice. and "." a cell as water. At the beginning, Yi and Han are both at a cell of water. Every day, some ice cells " X " will melt. An ice cell " X " melts if and only if in the previcus day, at least one of its adjacent grids is water. Here "adjacent" means on the top, bottom, left and right, at most 4 of them. An example of the ice melting process is shown above. Yi and Han can both swim to any adjacent water cell from their current position, but they cannot swim to any ice cells. They both swim very fast so that they can arrive at any cell on the lake instantly as long as two cells are connected with water cells. Given the initial position of Yi and Han, and the current status of the lake, decide that at which day Yi and Han can meet again. Input The first line contains two integers r and c,1r,c1500. The following r lines each contains c characters, which describes the initial status of the lake. " "means a water cell. " X " means an ice cell, "L" means a swan. Output The output only contains one integer t, which means that after t days, Y and Han can meet

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Machine Learning And Knowledge Discovery In Databases European Conference Ecml Pkdd 2022 Grenoble France September 19 23 2022 Proceedings Part 4 Lnai 13716

Authors: Massih-Reza Amini ,Stephane Canu ,Asja Fischer ,Tias Guns ,Petra Kralj Novak ,Grigorios Tsoumakas

1st Edition

3031264118, 978-3031264115

More Books

Students also viewed these Databases questions