-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathbard.java
43 lines (41 loc) · 1.59 KB
/
bard.java
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
40
41
42
43
import java.io.*;
import java.util.*;
public class bard {
public static void main(String[] args) throws Exception {
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
int n = Integer.parseInt(in.readLine());
long[] songs = new long[n];
int total = 0;
int e = Integer.parseInt(in.readLine());
for(int i = 0; i < e; i++) {
StringTokenizer st = new StringTokenizer(in.readLine());
int k = Integer.parseInt(st.nextToken());
ArrayList<Integer> now = new ArrayList<Integer>();
while(st.hasMoreTokens()) {
int v = Integer.parseInt(st.nextToken());
now.add(v);
}
if(!now.contains(1)) {
for(int u = 0; u < now.size(); u++) {
for(int v = u + 1; v < now.size(); v++) {
songs[now.get(u) - 1] |= songs[now.get(v) - 1];
songs[now.get(v) - 1] |= songs[now.get(u) - 1];
}
}
}
if(now.contains(1)) {
total++;
for(int v = 0; v < songs.length; v++) {
if(now.contains(v+1)) {
songs[v] += (long) Math.pow(2, total - 1);
}
}
}
}
for(int i = 0; i < songs.length; i++)
if(songs[i] == Math.pow(2, total) - 1)
out.println(i+1);
out.close();
}
}