-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathViralTransmission.java
More file actions
39 lines (37 loc) · 1010 Bytes
/
ViralTransmission.java
File metadata and controls
39 lines (37 loc) · 1010 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package company;
import java.util.*;
/**
* @Author: Wenhang Chen
* @Description:
* @Date: Created in 20:00 4/7/2020
* @Modified by:
*/
public class ViralTransmission {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int m = sc.nextInt();
int f = sc.nextInt();
boolean[] virus = new boolean[n];
int[] flag = new int[n];
virus[f] = true;
for (int i = 0; i < m; i++) {
int q = sc.nextInt();
boolean signal = false;
for (int j = 0; j < q; j++) {
flag[j] = sc.nextInt();
if (virus[flag[j]]) signal = true;
}
if (signal) {
for (int j = 0; j < q; j++) {
virus[flag[j]] = true;
}
}
}
int sum = 0;
for (int i = 0; i < n; i++) {
if (virus[i]) sum++;
}
System.out.println(sum);
}
}