#K77632. Water Flow in Pipeline

    ID: 34908 Type: Default 1000ms 256MiB

Water Flow in Pipeline

Water Flow in Pipeline

In this problem, you are given a string representing a pipeline. Each character in the string corresponds to a component of the pipeline:

  • A: a water source.
  • T: a target tap where water should arrive.
  • B: a blocker that interrupts the water flow.
  • Other characters (such as ., -, |) denote parts of the pipeline through which water can flow.

The water can flow between adjacent positions (left and right neighbors). The task is to determine if there exists a continuous path (using adjacent steps) from any source A to any tap T without crossing a blocker B.

Formally, let the pipeline be a string of length n. For indices i and j such that 0 ≤ i, j < n, there is an edge between i and i+1 if the corresponding character is not a blocker. This can be understood as a graph connectivity problem where you need to determine if any A is connected to any T through allowed moves. You may find the following LaTeX representation useful:

$$\text{Let } G = (V,E) \text{ where } V = \{0,1,\ldots,n-1\} \text{ and } \{i, i+1\} \in E \text{ if } pipeline[i+1] \neq 'B' \text{ and } pipeline[i] \neq 'B'.$$

inputFormat

The input consists of a single line containing the pipeline string.

Example: A.-|.-T

outputFormat

Output a single line: True if there is a continuous water flow from at least one source (A) to at least one target (T), and False otherwise.

## sample
A.-|.-T
True