diff --git "a/Seol-JY/202511/23 BOJ G4 \354\235\264\353\266\204 \352\267\270\353\236\230\355\224\204.md\342\200\216" "b/Seol-JY/202511/23 BOJ G4 \354\235\264\353\266\204 \352\267\270\353\236\230\355\224\204.md\342\200\216" new file mode 100644 index 00000000..12f0f2ca --- /dev/null +++ "b/Seol-JY/202511/23 BOJ G4 \354\235\264\353\266\204 \352\267\270\353\236\230\355\224\204.md\342\200\216" @@ -0,0 +1,73 @@ +```java +import java.io.*; +import java.util.*; + +public class Main { + static ArrayList[] graph; + static int[] color; + + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringBuilder sb = new StringBuilder(); + + int K = Integer.parseInt(br.readLine()); + + while(K-- > 0) { + StringTokenizer st = new StringTokenizer(br.readLine()); + int V = Integer.parseInt(st.nextToken()); + int E = Integer.parseInt(st.nextToken()); + + graph = new ArrayList[V + 1]; + color = new int[V + 1]; + + for(int i = 1; i <= V; i++) { + graph[i] = new ArrayList<>(); + } + + for(int i = 0; i < E; i++) { + st = new StringTokenizer(br.readLine()); + int u = Integer.parseInt(st.nextToken()); + int v = Integer.parseInt(st.nextToken()); + graph[u].add(v); + graph[v].add(u); + } + + boolean isBipartite = true; + for(int i = 1; i <= V; i++) { + if(color[i] == 0) { + if(!bfs(i)) { + isBipartite = false; + break; + } + } + } + + sb.append(isBipartite ? "YES" : "NO").append("\n"); + } + + System.out.print(sb); + } + + static boolean bfs(int start) { + ArrayDeque q = new ArrayDeque<>(); + q.offer(start); + color[start] = 1; + + while(!q.isEmpty()) { + int cur = q.poll(); + + for(int next : graph[cur]) { + if(color[next] == 0) { + color[next] = -color[cur]; + q.offer(next); + } else if(color[next] == color[cur]) { + return false; + } + } + } + + return true; + } +} + +```