diff --git "a/khj20006/202509/06 BOJ G2 \353\251\200\354\247\200\353\247\214 \352\260\200\352\271\214\354\232\264 \354\202\254\354\235\264.md" "b/khj20006/202509/06 BOJ G2 \353\251\200\354\247\200\353\247\214 \352\260\200\352\271\214\354\232\264 \354\202\254\354\235\264.md" new file mode 100644 index 00000000..4d4aef08 --- /dev/null +++ "b/khj20006/202509/06 BOJ G2 \353\251\200\354\247\200\353\247\214 \352\260\200\352\271\214\354\232\264 \354\202\254\354\235\264.md" @@ -0,0 +1,111 @@ +```java +import java.util.*; +import java.io.*; + +class IOController { + BufferedReader br; + BufferedWriter bw; + StringTokenizer st; + + public IOController() { + br = new BufferedReader(new InputStreamReader(System.in)); + bw = new BufferedWriter(new OutputStreamWriter(System.out)); + st = new StringTokenizer(""); + } + + String nextLine() throws Exception { + String line = br.readLine(); + st = new StringTokenizer(line); + return line; + } + + String nextToken() throws Exception { + while (!st.hasMoreTokens()) nextLine(); + return st.nextToken(); + } + + int nextInt() throws Exception { + return Integer.parseInt(nextToken()); + } + + long nextLong() throws Exception { + return Long.parseLong(nextToken()); + } + + double nextDouble() throws Exception { + return Double.parseDouble(nextToken()); + } + + void close() throws Exception { + bw.flush(); + bw.close(); + } + + void write(String content) throws Exception { + bw.write(content); + } + +} + +public class Main { + + static IOController io; + + // + + static int N; + static List[] graph; + static List list; + + public static void main(String[] args) throws Exception { + + io = new IOController(); + + N = io.nextInt(); + list = new ArrayList<>(); + graph = new List[N+1]; + for(int i=1;i<=N;i++) graph[i] = new ArrayList<>(); + for(int i=1;i q = new ArrayDeque<>(); + boolean[] vis = new boolean[N+1]; + q.offer(new int[]{1,0}); + vis[1] = true; + while(!q.isEmpty()) { + int[] cur = q.poll(); + int n = cur[0], v = cur[1]; + list.add(v); + for(int[] e:graph[n]) if(!vis[e[0]]) { + vis[e[0]] = true; + q.offer(new int[]{e[0],v^e[1]}); + } + } + Collections.sort(list); + + long ans = 0, cnt = 1; + int prev = list.get(0); + for(int i=1;i