-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathSB_258711.java
More file actions
30 lines (25 loc) Β· 1.11 KB
/
SB_258711.java
File metadata and controls
30 lines (25 loc) Β· 1.11 KB
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
import java.util.HashMap;
public class SB_258711 {
static HashMap<Integer, int[]> graph = new HashMap<>();
private static void cntInOutLink(int node, int type) {
int[] cnt = graph.getOrDefault(node, new int[]{0, 0}); // cnt[0]: μ§μΆμ°¨μ, cnt[1]: μ§μ
μ°¨μ
cnt[type]++; // ν΄λΉνλ νμ
κ°++
graph.put(node, cnt);
}
public static int[] solution(int[][] edges) {
int[] ans = {0, 0, 0, 0};
// λ
Έλλ€μ μ§μ
,μ§μΆ μ°¨μ μΈκΈ°
for (int[] e : edges) {
cntInOutLink(e[0], 0); // λκ°λ κ°μ
cntInOutLink(e[1], 1); // λ€μ΄μ€λ κ°μ
}
for (Integer key : graph.keySet()) {
int[] degree = graph.get(key);
if (degree[0] >=2 && degree[1]==0) ans[0] = key; // μμ± μ μ
else if (degree[0]==0 && degree[1] > 0) ans[2]++; // λ§λ κ·Έλν
else if (degree[0]>=2 && degree[1] >=2) ans[3]++; // 8μ κ·Έλν
}
ans[1] = graph.get(ans[0])[0] - ans[2] - ans[3];
return ans;
}
}