PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#DSU0000019. Những người nghi nhiễm (The Suspects)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Những người nghi nhiễm (The Suspects)
The Suspects
Source: POJ
Version: Phuoc Hung OJ Extended
Problem Statement
There are students numbered from to . Student is known to be a suspect for an infectious disease. There are student groups. If any student in a group is a suspect, every other student in that group also becomes a suspect. This rule propagates through groups that share members.
Determine the total number of suspected students.
Input
The first line contains two integers . Each of the next lines describes one group: an integer giving its size, followed by the indices of its members.
Output
Print the number of suspected students, including student .
Subtasks
- Subtask 1 (20 points): ; ; ; for every member; no duplicate student index within a group.
- Subtask 2 (30 points): ; ; ; for every member; no duplicate student index within a group.
- Subtask 3 (50 points): ; ; ; for every member; no duplicate student index within a group.
Examples
Input
100 4
2 1 2
5 10 13 11 12 14
2 0 1
2 99 2
Output
4
Explanation
Student 0 shares a group with 1; 1 with 2; 2 with 99. Exactly {0,1,2,99} are suspected.