This page is still under construction.

Parts of this page are still being built. What you see may change.

Export Estimate

Time limit4sMemory limit512 MB

Summary
For each threshold query, count the vertices and edges left after deleting low-priority streets and contracting degree-two vertices in index order.
Level

Hard8 of 10

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

Problem

Luka runs a geographic data company. The company maintains a detailed city map and exports the data to interested parties. Most clients do not want the complete map. They want a simplified map that keeps only the major streets.

The city map is an undirected graph with nn intersections, numbered from 11 to nn, and mm two-way streets. Every street carries a priority, which is a non-negative integer. A client who requests a map picks a threshold priority pp. The original map is copied, and the exported map is produced by the following procedure.

  1. Delete every street whose priority is lower than pp.

  2. Process the intersections ii in the order i=1,2,…,ni = 1, 2, \ldots, n.

    1. If intersection ii has no street attached to it, delete intersection ii.

    2. If intersection ii has exactly two different streets xx and yy attached to it, where xx leads to intersection aa and yy leads to intersection bb, and both aa and bb differ from ii, contract intersection ii as follows.

      1. Delete streets xx and yy.
      2. Delete intersection ii.
      3. Add a new street zz connecting intersections aa and bb.

The picture shows threshold priority 9595 applied to the map of the second example.

The initial map has no loop (a street joining an intersection to itself) and no parallel streets (more than one street between the same pair of intersections), but contraction can create both. In the second rule of step 2 neither xx nor yy can be a loop, because aa and bb both differ from ii, yet the new street zz can be a loop, because aa and bb may be equal.

You are given the map and a sequence of export requests. For each request, report how many intersections and how many streets the exported map has.

Input

The first line contains the number of intersections nn and the number of streets mm. (1≤n≤300 0001 \le n \le 300\,000, 1≤m≤300 0001 \le m \le 300\,000)

Each of the next mm lines contains three integers aa, bb and pp. (1≤a,b≤n1 \le a, b \le n, 0≤p≤300 0000 \le p \le 300\,000) They describe a street of priority pp connecting intersections aa and bb. No street joins an intersection to itself, and there is at most one street between any two intersections.

The next line contains the number of export requests qq. (1≤q≤300 0001 \le q \le 300\,000)

The last line contains qq integers. The kk-th integer tkt_k is the threshold priority of the kk-th request. (0≤tk≤300 0000 \le t_k \le 300\,000)

Output

Print qq lines. On the kk-th line print the number of intersections and the number of streets of the map exported for the kk-th request, separated by a space.

Examples6

  1. Example 1

    Input
    6 7
    1 2 20
    2 3 80
    2 5 100
    3 5 50
    3 4 100
    5 6 90
    4 6 100
    4
    25 75 85 95
    
    Expected output
    2 3
    1 1
    2 1
    4 2
    
  2. Example 2

    Input
    10 14
    2 7 150
    1 2 100
    2 3 150
    3 1 200
    1 4 60
    4 5 20
    2 5 100
    5 6 90
    6 7 120
    7 5 130
    6 8 50
    8 9 200
    9 10 200
    10 7 200
    5
    300 50 95 100 110
    
    Expected output
    0 0
    6 9
    4 5
    4 5
    5 4
    
  3. Example 3

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

    Input
    3 3
    1 2 10
    2 3 10
    3 1 7
    3
    0 8 11
    
    Expected output
    1 1
    2 1
    0 0
    
  5. Example 5

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

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