Time Limit: 2 sec / Memory Limit: 1024 MB
配点 : 200 点
問題文
1 から N までの番号がついた N 個の数列が与えられます。
数列 i は、長さが L_i で j (1 \leq j \leq L_i) 番目の要素が a_{i,j} であるような数列です。
数列 i と 数列 j は、 L_i = L_j かつすべての k (1 \leq k \leq L_i) に対して a_{i,k} = a_{j,k} が成り立つ時に同じであるとみなします。
同じ数列は 1 種類として数えるとき、数列 1 から 数列 N の中に全部で何種類の数列がありますか?
制約
- 1 \leq N \leq 2 \times 10^5
- 1 \leq L_i \leq 2 \times 10^5 (1 \leq i \leq N)
- 0 \leq a_{i,j} \leq 10^{9} (1 \leq i \leq N, 1 \leq j \leq L_i)
- すべての数列の要素の個数の和、すなわち \sum_{i=1}^N L_i は 2 \times 10^5 を超えない。
- 入力はすべて整数である。
入力
入力は以下の形式で標準入力から与えられる。
N L_1 a_{1,1} a_{1,2} \dots a_{1,L_1} L_2 a_{2,1} a_{2,2} \dots a_{2,L_2} \vdots L_N a_{N,1} a_{N,2} \dots a_{N,L_N}
出力
数列の種類数を出力せよ。
入力例 1
4 2 1 2 2 1 1 2 2 1 2 1 2
出力例 1
3
入力例 1 で与えられている数列は以下の 4 個です。
- 数列 1 : (1, 2)
- 数列 2 : (1, 1)
- 数列 3 : (2, 1)
- 数列 4 : (1, 2)
このうち数列 1 と数列 4 は同じ数列で、それ以外は互いに異なる数列なので全部で 3 種類の数列があります。
入力例 2
5 1 1 1 1 1 2 2 1 1 3 1 1 1
出力例 2
4
入力例 2 で与えられている数列は以下の 5 個です。
- 数列 1 : (1)
- 数列 2 : (1)
- 数列 3 : (2)
- 数列 4 : (1, 1)
- 数列 5 : (1, 1, 1)
入力例 3
1 1 1
出力例 3
1
Score : 200 points
Problem Statement
You are given N sequences numbered 1 to N.
Sequence i has a length of L_i and its j-th element (1 \leq j \leq L_i) is a_{i,j}.
Sequence i and Sequence j are considered the same when L_i = L_j and a_{i,k} = a_{j,k} for every k (1 \leq k \leq L_i).
How many different sequences are there among Sequence 1 through Sequence N?
Constraints
- 1 \leq N \leq 2 \times 10^5
- 1 \leq L_i \leq 2 \times 10^5 (1 \leq i \leq N)
- 0 \leq a_{i,j} \leq 10^{9} (1 \leq i \leq N, 1 \leq j \leq L_i)
- The total number of elements in the sequences, \sum_{i=1}^N L_i, does not exceed 2 \times 10^5.
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
N L_1 a_{1,1} a_{1,2} \dots a_{1,L_1} L_2 a_{2,1} a_{2,2} \dots a_{2,L_2} \vdots L_N a_{N,1} a_{N,2} \dots a_{N,L_N}
Output
Print the number of different sequences.
Sample Input 1
4 2 1 2 2 1 1 2 2 1 2 1 2
Sample Output 1
3
Sample Input 1 contains four sequences:
- Sequence 1 : (1, 2)
- Sequence 2 : (1, 1)
- Sequence 3 : (2, 1)
- Sequence 4 : (1, 2)
Except that Sequence 1 and Sequence 4 are the same, these sequences are pairwise different, so we have three different sequences.
Sample Input 2
5 1 1 1 1 1 2 2 1 1 3 1 1 1
Sample Output 2
4
Sample Input 2 contains five sequences:
- Sequence 1 : (1)
- Sequence 2 : (1)
- Sequence 3 : (2)
- Sequence 4 : (1, 1)
- Sequence 5 : (1, 1, 1)
Sample Input 3
1 1 1
Sample Output 3
1