結果
問題 | No.408 五輪ピック |
ユーザー | Grenache |
提出日時 | 2016-08-06 10:00:16 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 559 ms / 5,000 ms |
コード長 | 2,869 bytes |
コンパイル時間 | 4,167 ms |
コンパイル使用メモリ | 80,000 KB |
実行使用メモリ | 57,008 KB |
最終ジャッジ日時 | 2024-04-24 18:08:51 |
合計ジャッジ時間 | 16,176 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 62 ms
37,272 KB |
testcase_01 | AC | 60 ms
37,704 KB |
testcase_02 | AC | 59 ms
36,976 KB |
testcase_03 | AC | 60 ms
37,440 KB |
testcase_04 | AC | 57 ms
37,036 KB |
testcase_05 | AC | 485 ms
53,972 KB |
testcase_06 | AC | 378 ms
50,380 KB |
testcase_07 | AC | 467 ms
51,044 KB |
testcase_08 | AC | 422 ms
49,176 KB |
testcase_09 | AC | 429 ms
48,896 KB |
testcase_10 | AC | 374 ms
50,212 KB |
testcase_11 | AC | 369 ms
49,724 KB |
testcase_12 | AC | 476 ms
52,036 KB |
testcase_13 | AC | 480 ms
53,036 KB |
testcase_14 | AC | 281 ms
47,048 KB |
testcase_15 | AC | 493 ms
54,812 KB |
testcase_16 | AC | 494 ms
54,760 KB |
testcase_17 | AC | 493 ms
52,768 KB |
testcase_18 | AC | 500 ms
54,788 KB |
testcase_19 | AC | 524 ms
54,376 KB |
testcase_20 | AC | 302 ms
49,224 KB |
testcase_21 | AC | 266 ms
48,564 KB |
testcase_22 | AC | 383 ms
49,472 KB |
testcase_23 | AC | 559 ms
57,008 KB |
testcase_24 | AC | 466 ms
53,436 KB |
testcase_25 | AC | 483 ms
54,168 KB |
testcase_26 | AC | 529 ms
56,344 KB |
testcase_27 | AC | 496 ms
54,880 KB |
testcase_28 | AC | 412 ms
50,376 KB |
testcase_29 | AC | 418 ms
50,328 KB |
testcase_30 | AC | 58 ms
37,644 KB |
testcase_31 | AC | 57 ms
37,452 KB |
ソースコード
import java.io.*; import java.util.*; public class Main_yukicoder408_2 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); Printer pr = new Printer(System.out); int n = sc.nextInt(); int m = sc.nextInt(); List<List<Integer>> edges = new ArrayList<>(n); for (int i = 0; i < n; i++) { edges.add(null); } int[] a = new int[m]; int[] b = new int[m]; for (int i = 0; i < m; i++) { a[i] = sc.nextInt() - 1; b[i] = sc.nextInt() - 1; if (edges.get(a[i]) == null) { edges.set(a[i], new ArrayList<>()); } if (edges.get(b[i]) == null) { edges.set(b[i], new ArrayList<>()); } edges.get(a[i]).add(b[i]); edges.get(b[i]).add(a[i]); } List<List<Integer>> edges2 = new ArrayList<>(n); for (int i = 0; i < n; i++) { edges2.add(null); } for (int e : edges.get(0)) { for (int e2 : edges.get(e)) { if (e2 != 0) { if (edges2.get(e2) == null) { edges2.set(e2, new ArrayList<>(edges.get(e2).size())); } edges2.get(e2).add(e); } } } for (int i = 1; i < m; i++) { int ii = a[i]; int jj = b[i]; if (ii == 0 || jj == 0 || edges2.get(ii) == null || edges2.get(jj) == null) { continue; } for (int e : edges2.get(ii)) { if (e == 0) { continue; } for (int e2 : edges2.get(jj)) { if (e2 == 0) { continue; } if (e != e2 && e != jj && e2 != ii) { pr.println("YES"); pr.close(); sc.close(); return; } } } } pr.println("NO"); pr.close(); sc.close(); } @SuppressWarnings("unused") private static class Scanner { BufferedReader br; Iterator<String> it; Scanner (InputStream in) { br = new BufferedReader(new InputStreamReader(in), 128); } String next() throws RuntimeException { try { if (it == null || !it.hasNext()) { // it = Arrays.asList(br.readLine().split(" ")).iterator(); it = Arrays.asList(br.readLine().split("\\p{javaWhitespace}+")).iterator(); } return it.next(); } catch (IOException e) { throw new IllegalStateException(); } } int nextInt() throws RuntimeException { return Integer.parseInt(next()); } long nextLong() throws RuntimeException { return Long.parseLong(next()); } float nextFloat() throws RuntimeException { return Float.parseFloat(next()); } double nextDouble() throws RuntimeException { return Double.parseDouble(next()); } void close() { try { br.close(); } catch (IOException e) { // throw new IllegalStateException(); } } } private static class Printer extends PrintWriter { Printer(PrintStream out) { super(out); } } }