Under construction

Still being built. Things may change

Traffic

Time limit5sMemory limit128 MB

Summary
Given a planar graph of junctions on an island with one-way and two-way streets, count for each western-side junction how many eastern-side junctions it can reach, exploiting planarity and geometric structure since streets cannot cross.
Level

Hard8 of 10

Topics
Graph, DFS, Union-find
Solved
No attempts yet

Problem

The center of Gdynia lies on an island in the middle of the Kacza river. Every morning thousands of cars cross the island from the residential districts on the western bank (entering through junctions on the western side of the island) to the industrial areas on the eastern bank (leaving through junctions on the eastern side).

The island is a rectangle whose sides are parallel to the axes. We model it as an A×BA \times B rectangle in the Cartesian plane whose opposite corners are (0,0)(0, 0) and (A,B)(A, B).

There are nn junctions on the island, numbered from 11 to nn. Junction ii has coordinates (xi,yi)(x_i, y_i). A junction with coordinates (0,y)(0, y) lies on the western side of the island; a junction with coordinates (A,y)(A, y) lies on the eastern side. Junctions are connected by streets, each a straight segment joining two junctions. A street is either one-way or two-way. No two streets share any point other than a common endpoint at a junction (there are no bridges or tunnels). Nothing else about the network is assumed: streets may run along a bank, and a junction may have no incoming or outgoing streets.

For every junction on the western side, determine how many junctions on the eastern side are reachable from it.

Input

The first line contains four integers nn, mm, AA, BB (1≤n≤300 0001 \le n \le 300\,000, 0≤m≤900 0000 \le m \le 900\,000, 1≤A,B≤1091 \le A, B \le 10^9): the number of junctions, the number of streets, and the dimensions of the island.

Each of the next nn lines contains two integers xix_i, yiy_i (0≤xi≤A0 \le x_i \le A, 0≤yi≤B0 \le y_i \le B), the coordinates of junction ii. No two junctions share the same coordinates.

Each of the next mm lines contains three integers cic_i, did_i, kik_i (1≤ci,di≤n1 \le c_i, d_i \le n, ci≠dic_i \ne d_i, ki∈{1,2}k_i \in \{1, 2\}) describing a street between junctions cic_i and did_i. If ki=1k_i = 1 the street is one-way from cic_i to did_i; if ki=2k_i = 2 it can be driven in both directions. Each unordered pair {ci,di}\{c_i, d_i\} appears at most once.

At least one junction on the western side can reach some junction on the eastern side.

Output

Print one line for each junction on the western side. Each line contains the number of junctions on the eastern side reachable from that junction. Output the western junctions in order of decreasing yy-coordinate.

Hint

Examples5

  1. Example 1

    Input
    12 13 7 9
    0 1
    0 3
    2 2
    5 2
    7 1
    7 4
    7 6
    7 7
    3 5
    0 5
    0 9
    3 9
    1 3 2
    3 2 1
    3 4 1
    4 5 1
    5 6 1
    9 3 1
    9 4 1
    9 7 1
    9 12 2
    10 9 1
    11 12 1
    12 8 1
    12 10 1
    
    Expected output
    4
    4
    0
    2
    
  2. Example 2

    Input
    5 3 1 3
    0 0
    0 1
    0 2
    1 0
    1 1
    1 4 1
    1 5 2
    3 5 2
    
    Expected output
    2
    0
    2
    
  3. Example 3

    Input
    5 3 6 5
    0 5
    0 0
    3 1
    6 0
    6 2
    1 3 1
    3 4 1
    3 5 2
    
    Expected output
    2
    0
    
  4. Example 4

    Input
    7 5 5 5
    0 5
    0 3
    0 1
    5 4
    5 2
    2 5
    2 1
    1 6 1
    6 4 1
    6 7 2
    7 5 1
    2 7 1
    
    Expected output
    2
    2
    0
    
  5. Example 5

    Input
    3 1 3 2
    0 0
    0 2
    3 1
    2 3 1
    
    Expected output
    1
    0