#P9638. Dynamic Friends and Uniforms

    ID: 22785 Type: Default 1000ms 256MiB

Dynamic Friends and Uniforms

Dynamic Friends and Uniforms

There are n students and m friendship pairs. For the i-th friendship pair, there is an associated sensitivity value \(k_i\). Two students are called friends if they are directly connected by a friendship pair, and they are called good friends if they are connected directly or indirectly through friendship pairs.

Before the military training, students go to collect uniforms. When a student collects a uniform of size \(p\), every friendship (that is currently active) with sensitivity value less than \(p\) will be broken temporarily. However, when the next student collects a uniform, all the temporarily broken relationships (i.e. those broken in previous uniform events) are restored. In contrast, if a relationship that is temporarily broken is updated later (see operation 3) then it will be broken permanently and will not be restored.

There are q operations in total. Operations are of the following types:

  • 1 x: A student collects a uniform of size \(x\). Before processing this operation, all relationships that are not permanently broken are restored. Then, for every active (i.e. not permanently broken) friendship, if its sensitivity value is less than \(x\), the friendship is temporarily broken.
  • 2 x: Query how many good friends student \(x\) has (including himself). Two students are good friends if they are connected through active friendships. Active friendships are those that are not permanently broken and not temporarily broken by the most recent uniform operation.
  • 3 x y: The sensitivity value of the x-th friendship is updated to \(y\). Note that the relative order of all current sensitivity values must be preserved. In addition, if the x-th friendship was temporarily broken at the time of the update, it becomes permanently broken (i.e. even if future uniform events would normally restore it, it remains broken forever).

Note: "Friends" means directly connected, while "good friends" are those in the same connected component via active relationships.

Input Format: The first line contains three integers \(n\), \(m\) and \(q\). The next \(m\) lines each contain three integers \(u\), \(v\) and \(k\) denoting an friendship between students \(u\) and \(v\) with sensitivity value \(k\). Each of the following \(q\) lines contains an operation in one of the three forms described above.

Output Format: For each operation of type 2, output on a new line the number of good friends of the queried student.

inputFormat

The first line contains three integers \(n\), \(m\), \(q\) separated by spaces.

The next \(m\) lines each contain three integers \(u\), \(v\), \(k\) indicating a friendship between student \(u\) and student \(v\) with sensitivity value \(k\).

The following \(q\) lines each contain an operation, which can be one of the following forms:

  • 1 x
  • 2 x
  • 3 x y

It is guaranteed that the update operations (type 3) provide a new sensitivity value \(y\) that maintains the relative order of all sensitivity values.

outputFormat

For each operation of type 2, output a single integer on a new line, representing the number of good friends (including the student himself) in the current active network.

sample

5 4 6
1 2 3
2 3 5
3 4 2
4 5 4
2 1
1 4
2 2
3 1 7
1 5
2 5
5

2 1

</p>