#P4700. Reachable East Points

    ID: 17944 Type: Default 1000ms 256MiB

Reachable East Points

Reachable East Points

You are given n points in the Cartesian plane. The i-th point has coordinates \( (x_i,y_i) \) and all points lie inside the rectangle with opposite vertices \((0,0)\) and \((A,B)\). A point is considered to be on the west side if its \(x\)-coordinate equals \(0\) and on the east side if its \(x\)-coordinate equals \(A\).

There are also m edges between these points. Each edge can be either directed or undirected, and it is guaranteed that the edges do not intersect except possibly at the endpoints. For a directed edge, the connection is only valid in the given direction; for an undirected edge, the connection works in both directions.

Your task is to determine, for each point on the west side, how many distinct east side points are reachable by traversing the edges (following the edge directions when applicable).

Note: The graph may contain both directed and undirected edges.

inputFormat

The first line contains four integers \(n\), \(m\), \(A\), and \(B\), where \(n\) is the number of points, \(m\) is the number of edges, and \((0,0)\) and \((A,B)\) are the coordinates of the two opposite vertices of the bounding rectangle.

The next \(n\) lines each contain two integers \(x_i\) and \(y_i\) representing the coordinates of the \(i\)-th point (1-indexed).

The following \(m\) lines each contain three integers \(u\), \(v\), and \(t\). Here, \(u\) and \(v\) denote the endpoints of an edge (by their point indices). If \(t = 1\), the edge is directed from \(u\) to \(v\); if \(t = 0\), the edge is undirected (thus connecting \(u\) and \(v\) in both directions).

outputFormat

For each point that is on the west side (i.e. points with \(x_i = 0\)), output a single line containing one integer: the number of distinct east side points (i.e. points with \(x_i = A\)) that are reachable from that point following the edges (and respecting their direction).

sample

5 4 10 10
0 5
10 5
5 5
0 0
10 0
1 3 0
3 2 1
3 4 0
4 5 1
2

2

</p>