結果
問題 | No.2202 贅沢てりたまチキン |
ユーザー | tenten |
提出日時 | 2023-04-21 11:31:58 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 375 ms / 2,000 ms |
コード長 | 2,629 bytes |
コンパイル時間 | 2,419 ms |
コンパイル使用メモリ | 92,008 KB |
実行使用メモリ | 62,340 KB |
最終ジャッジ日時 | 2024-04-24 01:12:44 |
合計ジャッジ時間 | 9,148 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 45 ms
37,116 KB |
testcase_01 | AC | 43 ms
37,216 KB |
testcase_02 | AC | 45 ms
37,060 KB |
testcase_03 | AC | 46 ms
37,048 KB |
testcase_04 | AC | 46 ms
36,908 KB |
testcase_05 | AC | 45 ms
36,976 KB |
testcase_06 | AC | 44 ms
37,104 KB |
testcase_07 | AC | 47 ms
36,808 KB |
testcase_08 | AC | 48 ms
37,144 KB |
testcase_09 | AC | 46 ms
36,800 KB |
testcase_10 | AC | 51 ms
38,508 KB |
testcase_11 | AC | 46 ms
36,800 KB |
testcase_12 | AC | 45 ms
36,864 KB |
testcase_13 | AC | 45 ms
37,100 KB |
testcase_14 | AC | 360 ms
61,884 KB |
testcase_15 | AC | 346 ms
62,340 KB |
testcase_16 | AC | 290 ms
48,484 KB |
testcase_17 | AC | 315 ms
54,364 KB |
testcase_18 | AC | 225 ms
45,912 KB |
testcase_19 | AC | 240 ms
48,172 KB |
testcase_20 | AC | 318 ms
48,204 KB |
testcase_21 | AC | 315 ms
48,232 KB |
testcase_22 | AC | 280 ms
46,876 KB |
testcase_23 | AC | 288 ms
47,080 KB |
testcase_24 | AC | 287 ms
46,868 KB |
testcase_25 | AC | 375 ms
48,612 KB |
testcase_26 | AC | 331 ms
55,220 KB |
testcase_27 | AC | 322 ms
55,140 KB |
ソースコード
import java.io.*; import java.util.*; import java.util.stream.*; public class Main { public static void main(String[] args) throws Exception { Scanner sc = new Scanner(); int n = sc.nextInt(); int m = sc.nextInt(); UnionFindTree uft = new UnionFindTree(n * 2); for (int i = 0; i < m; i++) { int a = sc.nextInt() - 1; int b = sc.nextInt() - 1; uft.unite(a, b + n); uft.unite(a + n, b); } for (int i = 0; i < n; i++) { if (!uft.same(i, n + i)) { System.out.println("No"); return; } } System.out.println("Yes"); } static class UnionFindTree { int[] parents; public UnionFindTree(int size) { parents = new int[size]; for (int i = 0; i < size; i++) { parents[i] = i; } } public int find(int x) { if (parents[x] == x) { return x; } else { return parents[x] = find(parents[x]); } } public boolean same(int x, int y) { return find(x) == find(y); } public void unite(int x, int y) { if (!same(x, y)) { parents[find(x)] = find(y); } } } } class Utilities { static String arrayToLineString(Object[] arr) { return Arrays.stream(arr).map(x -> x.toString()).collect(Collectors.joining("\n")); } static String arrayToLineString(int[] arr) { return String.join("\n", Arrays.stream(arr).mapToObj(String::valueOf).toArray(String[]::new)); } } class Scanner { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""); StringBuilder sb = new StringBuilder(); public Scanner() throws Exception { } public int nextInt() throws Exception { return Integer.parseInt(next()); } public long nextLong() throws Exception { return Long.parseLong(next()); } public double nextDouble() throws Exception { return Double.parseDouble(next()); } public int[] nextIntArray() throws Exception { return Stream.of(br.readLine().split(" ")).mapToInt(Integer::parseInt).toArray(); } public String next() throws Exception { while (!st.hasMoreTokens()) { st = new StringTokenizer(br.readLine()); } return st.nextToken(); } }