結果

問題 No.408 五輪ピック
ユーザー GrenacheGrenache
提出日時 2016-08-06 02:00:04
言語 Java21
(openjdk 21)
結果
AC  
実行時間 751 ms / 5,000 ms
コード長 2,527 bytes
コンパイル時間 3,875 ms
コンパイル使用メモリ 80,160 KB
実行使用メモリ 59,352 KB
最終ジャッジ日時 2024-04-24 17:20:59
合計ジャッジ時間 15,491 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 51 ms
37,092 KB
testcase_01 AC 52 ms
37,356 KB
testcase_02 AC 53 ms
37,532 KB
testcase_03 AC 55 ms
37,756 KB
testcase_04 AC 56 ms
37,092 KB
testcase_05 AC 396 ms
54,184 KB
testcase_06 AC 308 ms
50,068 KB
testcase_07 AC 374 ms
50,756 KB
testcase_08 AC 347 ms
51,100 KB
testcase_09 AC 357 ms
49,812 KB
testcase_10 AC 335 ms
50,252 KB
testcase_11 AC 315 ms
48,780 KB
testcase_12 AC 478 ms
51,168 KB
testcase_13 AC 483 ms
52,560 KB
testcase_14 AC 234 ms
47,452 KB
testcase_15 AC 399 ms
54,616 KB
testcase_16 AC 397 ms
53,020 KB
testcase_17 AC 400 ms
50,844 KB
testcase_18 AC 413 ms
53,760 KB
testcase_19 AC 421 ms
54,292 KB
testcase_20 AC 256 ms
47,988 KB
testcase_21 AC 234 ms
47,644 KB
testcase_22 AC 311 ms
50,432 KB
testcase_23 AC 459 ms
53,636 KB
testcase_24 AC 406 ms
53,008 KB
testcase_25 AC 500 ms
58,752 KB
testcase_26 AC 435 ms
53,572 KB
testcase_27 AC 751 ms
59,352 KB
testcase_28 AC 631 ms
57,980 KB
testcase_29 AC 534 ms
56,820 KB
testcase_30 AC 52 ms
37,624 KB
testcase_31 AC 53 ms
37,360 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.*;


public class Main_yukicoder408_1 {

    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();

    	@SuppressWarnings("unchecked")
		List<Integer> edges[] = new ArrayList[n];
    	for (int i = 0; i < n; i++) {
    		edges[i] = new ArrayList<>();
    	}

    	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;

    		edges[a[i]].add(b[i]);
    		edges[b[i]].add(a[i]);
    	}

    	List<Integer>[] edges2 = new ArrayList[n];
    	for (int i = 0; i < n; i++) {
    		edges2[i] = new ArrayList<>();
    	}

    	for (int e : edges[0]) {
    		for (int e2 : edges[e]) {
    			if (e2 != 0) {
    				edges2[e2].add(e);
    			}
    		}
    	}

    	for (int i = 0; i < m; i++) {
    		if (a[i] == 0 || b[i] == 0) {
    			continue;
    		}

    		for (int e : edges2[a[i]]) {
    			if (e == 0) {
    				continue;
    			}
    			for (int e2 : edges2[b[i]]) {
    				if (e2 == 0) {
    					continue;
    				}
    				if (e != e2 && e != b[i] && e2 != a[i]) {
    					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));
		}

		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);
		}
	}
}
0