#P2883. Cow Traffic Congestion

    ID: 16141 Type: Default 1000ms 256MiB

Cow Traffic Congestion

Cow Traffic Congestion

The bovine population boom on the farm has led to severe congestion on the cow trails. Farmer John wants to relieve the "traffic jams" during milking time by identifying the busiest trail.

Given a directed acyclic graph (DAG) with (N) intersections (numbered 1 through (N)) and (M) one-way trails, each trail connects a lower-numbered intersection to a higher-numbered intersection. The barn is located at intersection (N). Grazing locations are those intersections with no incoming trails. A path is defined as a sequence of trails from a grazing location to the barn.

For any trail ((u, v)), the number of paths that pass through it is given by:
[ dp_{in}(u) \times dp_{out}(v), ] where (dp_{in}(u)) is the number of paths from any grazing location to (u) and (dp_{out}(v)) is the number of paths from (v) to the barn.

Your task is to compute the maximum number of paths that use any one trail. The answer is guaranteed to fit in a signed 32-bit integer.

inputFormat

The first line contains two integers (N) and (M). Each of the following (M) lines contains two integers (u) and (v), indicating a one-way trail from intersection (u) to intersection (v) (with (u < v)).

outputFormat

Output a single integer: the maximum number of paths, among all trails, that pass through that trail.

sample

4 5
1 2
1 3
2 4
3 4
2 3
2