#P5443. St. Petersburg Bridges

    ID: 18675 Type: Default 1000ms 256MiB

St. Petersburg Bridges

St. Petersburg Bridges

St. Petersburg is built on \(n\) islands connected by \(m\) bridges. The islands are numbered from 1 to \(n\) and the bridges are numbered from 1 to \(m\). Each bridge connects two distinct islands and has a weight limit \(d_i\); that is, only cars with weight \(w \le d_i\) can cross that bridge. Over the years, some bridges have been renovated which may have increased or decreased their weight limits.

You are to design a module that supports the following two types of operations:

  1. Update: Change the weight limit of bridge \(b_j\) to \(r_j\).
  2. Query: For a car with weight \(w_j\) starting from island \(s_j\), count the number of distinct islands that are reachable via bridges satisfying the condition \(w_j \le d_i\).

You are required to answer all the queries of type 2.

inputFormat

The input begins with a line containing three integers \(n\), \(m\) and \(q\): the number of islands, bridges, and operations respectively.

Then \(m\) lines follow. Each line contains three integers \(u_i\), \(v_i\) and \(d_i\) indicating that there is a bridge connecting island \(u_i\) and island \(v_i\) with weight limit \(d_i\).

After that, there are \(q\) lines each describing an operation. There are two types of operations:
1 \(b_j\) \(r_j\): Update the weight limit of bridge \(b_j\) to \(r_j\).
2 \(s_j\) \(w_j\): Query how many islands are reachable from island \(s_j\) using only bridges with current weight limit at least \(w_j\).

outputFormat

For each query (operation of type 2), output a single integer on a new line denoting the number of islands reachable from the given starting island.

sample

5 5 5
1 2 10
2 3 5
3 4 7
4 5 3
1 5 8
2 1 6
1 2 12
2 3 5
1 5 2
2 4 3
3

4 5

</p>