結果
問題 | No.2202 贅沢てりたまチキン |
ユーザー | tenten |
提出日時 | 2024-04-30 15:17:13 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 381 ms / 2,000 ms |
コード長 | 2,451 bytes |
コンパイル時間 | 2,148 ms |
コンパイル使用メモリ | 78,412 KB |
実行使用メモリ | 74,436 KB |
最終ジャッジ日時 | 2024-04-30 15:17:24 |
合計ジャッジ時間 | 9,238 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 46 ms
50,276 KB |
testcase_01 | AC | 48 ms
50,412 KB |
testcase_02 | AC | 50 ms
50,100 KB |
testcase_03 | AC | 48 ms
50,508 KB |
testcase_04 | AC | 48 ms
50,512 KB |
testcase_05 | AC | 47 ms
50,340 KB |
testcase_06 | AC | 47 ms
50,304 KB |
testcase_07 | AC | 49 ms
50,436 KB |
testcase_08 | AC | 49 ms
50,316 KB |
testcase_09 | AC | 49 ms
49,896 KB |
testcase_10 | AC | 63 ms
50,048 KB |
testcase_11 | AC | 47 ms
50,268 KB |
testcase_12 | AC | 50 ms
50,396 KB |
testcase_13 | AC | 49 ms
50,312 KB |
testcase_14 | AC | 336 ms
74,436 KB |
testcase_15 | AC | 359 ms
72,860 KB |
testcase_16 | AC | 321 ms
58,692 KB |
testcase_17 | AC | 313 ms
65,180 KB |
testcase_18 | AC | 218 ms
56,332 KB |
testcase_19 | AC | 235 ms
58,512 KB |
testcase_20 | AC | 327 ms
59,016 KB |
testcase_21 | AC | 342 ms
58,752 KB |
testcase_22 | AC | 281 ms
58,544 KB |
testcase_23 | AC | 292 ms
58,484 KB |
testcase_24 | AC | 295 ms
58,932 KB |
testcase_25 | AC | 381 ms
58,636 KB |
testcase_26 | AC | 325 ms
66,384 KB |
testcase_27 | AC | 331 ms
66,136 KB |
ソースコード
import java.io.*; import java.util.*; import java.util.function.*; 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); while (m-- > 0) { uft.uniteAll(sc.nextInt() - 1, sc.nextInt() - 1); } boolean enable = true; for (int i = 0; i < n && enable; i++) { enable = uft.sameAll(i); } System.out.println(enable ? "Yes" : "No"); } static class UnionFindTree { int size; int[] parents; public UnionFindTree(int size) { this.size = size; parents = new int[size * 2]; for (int i = 0; i < size * 2; i++) { parents[i] = i; } } public int find(int x) { if (x == parents[x]) { return x; } else { return parents[x] = find(parents[x]); } } private boolean same(int x, int y) { return find(x) == find(y); } public boolean sameAll(int x) { return same(x, x + size); } private void unite(int x, int y) { if (!same(x, y)) { parents[find(x)] = find(y); } } public void uniteAll(int x, int y) { unite(x, y + size); unite(x + size, y); } } } class Scanner { BufferedReader br; StringTokenizer st = new StringTokenizer(""); StringBuilder sb = new StringBuilder(); public Scanner() { try { br = new BufferedReader(new InputStreamReader(System.in)); } catch (Exception e) { } } public int nextInt() { return Integer.parseInt(next()); } public long nextLong() { return Long.parseLong(next()); } public double nextDouble() { return Double.parseDouble(next()); } public String next() { try { while (!st.hasMoreTokens()) { st = new StringTokenizer(br.readLine()); } } catch (Exception e) { e.printStackTrace(); } finally { return st.nextToken(); } } }