#P8026. [ONTAK2015] Bajtocja

    ID: 9121 远端评测题 1000ms 256MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>2015并查集树上启发式合并哈希 hashing

[ONTAK2015] Bajtocja

Problem Description

You are given dd undirected graphs, each with nn vertices. Initially, there are no edges in any graph. Then there are mm operations. Each operation gives a,b,ka, b, k, meaning that an undirected edge is added between vertex aa and vertex bb in the kk-th graph. After each operation, you need to output the number of ordered pairs (a,b)(a, b) such that 1a,bn1 \leq a, b \leq n, and vertices aa and bb are connected in all dd graphs.

Input Format

The first line contains three integers d,n,md, n, m.

The next mm lines each contain three integers a,b,ka, b, k.

Output Format

Output mm lines. Each line contains one integer, representing the required value.

3 4 10
1 2 1
2 1 2
1 2 3
3 4 1
1 3 2
2 3 3
2 4 2
3 4 3
3 4 2
1 3 1
4
4
6
6
6
6
6
8
8
16

Hint

For 100%100\% of the testdata, 1d2001 \leq d \leq 200, 1n5×1031 \leq n \leq 5 \times 10^3, 1m1061 \leq m \leq 10^6, 1a,bn1 \leq a, b \leq n, 1kd1 \leq k \leq d.

Translated by ChatGPT 5