#K39732. Traffic Jam Detector
Traffic Jam Detector
Traffic Jam Detector
The city is developing a complex network of intersections connected by roads. Each road is directed and has an associated traffic intensity. A traffic jam at an intersection occurs when there are flows arriving from at least two different intersections through non-overlapping paths.
You are given a number of intersections and a list of roads. Each road is described by three integers: the starting intersection u, the ending intersection v, and the current traffic intensity w. Your task is to determine if there exists any intersection that receives incoming traffic from at least two different intersections. If such an intersection exists, output YES
; otherwise, output NO
.
Note: Two incoming roads are considered non-overlapping if they originate from different intersections. Formally, for an intersection \(v\), if there exist at least two distinct intersections \(u_1\) and \(u_2\) such that a road from \(u_1\) to \(v\) and a road from \(u_2\) to \(v\) exist, then a traffic jam occurs at \(v\).
inputFormat
The input is read from standard input. The first line contains two space-separated integers (n) and (m) denoting the number of intersections and the number of roads respectively. Each of the following (m) lines contains three space-separated integers (u), (v), and (w), representing a road from intersection (u) to intersection (v) with a traffic intensity of (w).
outputFormat
Output a single line to standard output. Print YES
if there exists an intersection that receives incoming roads from at least two different intersections (i.e. a traffic jam). Otherwise, print NO
.## sample
4 4
1 2 10
2 3 20
1 3 15
3 4 5
YES