#C7707. Mystic Island System Operations

    ID: 51608 Type: Default 1000ms 256MiB

Mystic Island System Operations

Mystic Island System Operations

You are given a system of M mystical islands connected by portals. Each portal connects two islands and has an associated power level. Initially, all portals have a power level of 0.

You are to perform two types of operations on this system:

  • Type 1 Operation: 1 p q k – Strengthen the portal connecting islands p and q by adding a power of k. Note that since the connection is undirected, the portal is uniquely defined by the unordered pair \((p,q)\). Formally, if \(p > q\), swap them so that the portal is always stored as \((\min(p,q), \max(p,q))\).
  • Type 2 Operation: 2 r – Query the total power connected to island r. The total power is defined as: \[ P(r)=\sum_{x \in N(r)} w\big(\min(r,x), \max(r,x)\big) \] where \(N(r)\) is the set of islands directly connected to island r and \(w(i,j)\) is the current power level of the portal between islands \(i\) and \(j\).

You need to simulate the operations and print the answer for every type 2 operation.

inputFormat

The input is read from stdin and is formatted as follows:

  1. An integer M representing the number of islands.
  2. An integer P representing the number of portals.
  3. P lines follow, each containing two integers a b indicating that there is a portal between islands a and b.
  4. An integer Q representing the number of operations.
  5. Q lines follow, each representing an operation. A line starting with 1 is followed by three integers p q k (strengthen operation), and a line starting with 2 is followed by a single integer r (query operation).

outputFormat

For each type 2 operation, output a line to stdout containing the total power for the specified island.

## sample
6
5
1 2
2 3
3 4
4 5
5 6
5
1 2 3 10
2 3
1 4 3 5
2 4
2 6
10

5 0

</p>