結果

問題 No.408 五輪ピック
ユーザー GrenacheGrenache
提出日時 2016-08-06 09:40:34
言語 Java21
(openjdk 21)
結果
AC  
実行時間 912 ms / 5,000 ms
コード長 3,076 bytes
コンパイル時間 3,518 ms
コンパイル使用メモリ 79,532 KB
実行使用メモリ 56,488 KB
最終ジャッジ日時 2024-04-24 18:07:58
合計ジャッジ時間 15,998 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 52 ms
37,436 KB
testcase_01 AC 52 ms
37,552 KB
testcase_02 AC 53 ms
37,516 KB
testcase_03 AC 54 ms
37,184 KB
testcase_04 AC 54 ms
37,424 KB
testcase_05 AC 482 ms
54,600 KB
testcase_06 AC 352 ms
50,732 KB
testcase_07 AC 429 ms
50,964 KB
testcase_08 AC 414 ms
51,496 KB
testcase_09 AC 407 ms
49,312 KB
testcase_10 AC 363 ms
50,516 KB
testcase_11 AC 349 ms
50,404 KB
testcase_12 AC 460 ms
53,092 KB
testcase_13 AC 439 ms
52,908 KB
testcase_14 AC 272 ms
48,568 KB
testcase_15 AC 454 ms
54,472 KB
testcase_16 AC 453 ms
53,996 KB
testcase_17 AC 482 ms
53,340 KB
testcase_18 AC 467 ms
51,600 KB
testcase_19 AC 464 ms
54,188 KB
testcase_20 AC 288 ms
49,488 KB
testcase_21 AC 247 ms
48,216 KB
testcase_22 AC 353 ms
49,920 KB
testcase_23 AC 485 ms
55,440 KB
testcase_24 AC 430 ms
54,664 KB
testcase_25 AC 525 ms
56,452 KB
testcase_26 AC 486 ms
54,212 KB
testcase_27 AC 912 ms
56,488 KB
testcase_28 AC 369 ms
50,796 KB
testcase_29 AC 379 ms
52,080 KB
testcase_30 AC 52 ms
37,224 KB
testcase_31 AC 55 ms
37,016 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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];
		int[] tmpa = new int[m];
		int[] tmpb = new int[m];
    	for (int i = 0; i < m; i++) {
//    		a[i] = sc.nextInt() - 1;
//    		b[i] = sc.nextInt() - 1;
    		int a = sc.nextInt() - 1;
    		int b = sc.nextInt() - 1;

//    		edges[a[i]].add(b[i]);
//    		edges[b[i]].add(a[i]);
    		if (edges.get(a) == null) {
    			edges.set(a, new ArrayList<>());
    		}
    		if (edges.get(b) == null) {
    			edges.set(b, new ArrayList<>());
    		}
    		edges.get(a).add(b);
    		edges.get(b).add(a);
    	}

    	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 < n; i++) {
    		for (int j : edges.get(i)) {
    			if (j == 0 || edges2.get(i) == null) {
    				continue;
    			}

        		for (int e : edges2.get(i)) {
        			if (e == 0 || edges2.get(j) == null) {
        				continue;
        			}
        			for (int e2 : edges2.get(j)) {
        				if (e2 == 0) {
        					continue;
        				}
        				if (e != e2 && e != j && e2 != 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), 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);
		}
	}
}
0