728x90
반응형
https://www.acmicpc.net/problem/14676
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Set;
import java.util.StringTokenizer;
public class Main {
static int N, M, K;
static ArrayList<ArrayList<Integer>> grapgh;
static ArrayList<Set<Integer>> remove;
static int[] seq;
static int[] build;
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine());
N = Integer.parseInt(st.nextToken());
M = Integer.parseInt(st.nextToken());
K = Integer.parseInt(st.nextToken());
seq = new int[N + 1];
build = new int[N + 1];
remove = new ArrayList<>();
grapgh = new ArrayList<>();
for (int i = 0; i < N + 1; i++) {
grapgh.add(new ArrayList<>());
remove.add(new HashSet<>());
}
while (M-- > 0) {
st = new StringTokenizer(br.readLine());
int u = Integer.parseInt(st.nextToken());
int v = Integer.parseInt(st.nextToken());
grapgh.get(u).add(v);
seq[v]++;
}
while (K-- > 0) {
st = new StringTokenizer(br.readLine());
int command = Integer.parseInt(st.nextToken());
int num = Integer.parseInt(st.nextToken());
if ((command == 1 && seq[num] != 0) ||
(command == 2 && build[num] == 0)) {
System.out.println("Lier!");
System.exit(0);
}
if (command == 1) {
build[num]++;
for (int next : grapgh.get(num)) {
if (!remove.get(next).contains(num)) {
remove.get(next).add(num);
}
if (seq[next] == 0)
continue;
seq[next]--;
}
} else {
build[num]--;
if (build[num] == 0) {
for (int next : grapgh.get(num)) {
remove.get(next).clear();
seq[next]++;
}
}
}
}
System.out.println("King-God-Emperor");
}
}
|
cs |
728x90
'Algorithm > BOJ' 카테고리의 다른 글
백준) 1074_Z (0) | 2023.05.16 |
---|---|
백준) 11003_최솟값 찾기 (2) | 2023.05.14 |
백준) 21276_계보 복원가 호석 (2) | 2023.05.13 |
백준) 1766_문제집 (1) | 2023.05.13 |
백준) 1005_ACM Craft (1) | 2023.05.13 |