結果

問題 No.408 五輪ピック
ユーザー uafr_cs
提出日時 2016-08-05 23:11:57
言語 Java
(openjdk 23)
結果
WA  
実行時間 -
コード長 1,413 bytes
コンパイル時間 2,438 ms
コンパイル使用メモリ 78,896 KB
実行使用メモリ 61,256 KB
最終ジャッジ日時 2024-11-07 01:11:47
合計ジャッジ時間 22,205 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 29 WA * 3
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.Scanner;
import java.util.Set;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		final int N = sc.nextInt();
		final int M = sc.nextInt();
		
		ArrayList<HashSet<Integer>> adj = new ArrayList<HashSet<Integer>>();
		for(int i = 0; i < N; i++){ adj.add(new HashSet<Integer>()); }
		
		for(int i = 0; i < M; i++){
			final int A = sc.nextInt() - 1;
			final int B = sc.nextInt() - 1;
			
			adj.get(A).add(B);
			adj.get(B).add(A);
		}
		//System.out.println(adj);
		
		ArrayList<HashSet<Integer>> to_1 = new ArrayList<HashSet<Integer>>();
		for(int i = 0; i < N; i++){ to_1.add(new HashSet<Integer>()); }
		
		for(int i = 1; i < N; i++){
			for(final int j : adj.get(i)){
				if(adj.get(j).contains(0)){
					to_1.get(i).add(j);
				}
			}
		}
		
		//System.out.println(to_1);
		
		for(int fst = 1; fst < N; fst++){
			for(final int snd : adj.get(fst)){
				final HashSet<Integer> fst_to_1 = to_1.get(fst);
				final HashSet<Integer> snd_to_1 = to_1.get(snd);
				
				//System.out.println(fst_to_1 + " " + snd_to_1);
				
				if(fst_to_1.isEmpty() || snd_to_1.isEmpty()){ continue; }
				
				if(!fst_to_1.equals(snd_to_1)){
					System.out.println("YES");
					return;
				}
			}
		}
		
		System.out.println("NO");
		return;
	}

}
0