結果

問題 No.408 五輪ピック
ユーザー uafr_csuafr_cs
提出日時 2016-08-05 23:16:04
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 2,588 bytes
コンパイル時間 2,079 ms
コンパイル使用メモリ 78,860 KB
実行使用メモリ 60,396 KB
最終ジャッジ日時 2024-04-24 16:59:17
合計ジャッジ時間 11,584 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 48 ms
36,560 KB
testcase_01 AC 49 ms
36,664 KB
testcase_02 AC 47 ms
36,792 KB
testcase_03 WA -
testcase_04 AC 53 ms
36,588 KB
testcase_05 AC 301 ms
50,560 KB
testcase_06 AC 313 ms
52,636 KB
testcase_07 AC 275 ms
50,212 KB
testcase_08 AC 272 ms
49,708 KB
testcase_09 AC 260 ms
50,020 KB
testcase_10 AC 288 ms
50,644 KB
testcase_11 AC 274 ms
50,040 KB
testcase_12 AC 378 ms
53,144 KB
testcase_13 AC 300 ms
50,324 KB
testcase_14 AC 204 ms
47,256 KB
testcase_15 AC 276 ms
50,532 KB
testcase_16 AC 297 ms
50,668 KB
testcase_17 AC 316 ms
51,600 KB
testcase_18 AC 307 ms
51,780 KB
testcase_19 AC 330 ms
52,072 KB
testcase_20 AC 215 ms
49,272 KB
testcase_21 AC 185 ms
45,392 KB
testcase_22 AC 272 ms
51,888 KB
testcase_23 AC 364 ms
58,080 KB
testcase_24 AC 364 ms
60,396 KB
testcase_25 AC 506 ms
55,516 KB
testcase_26 AC 477 ms
58,880 KB
testcase_27 AC 869 ms
57,224 KB
testcase_28 AC 233 ms
50,092 KB
testcase_29 AC 234 ms
50,364 KB
testcase_30 AC 49 ms
36,580 KB
testcase_31 AC 49 ms
37,028 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.BufferedReader;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.Scanner;
import java.util.Set;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) throws IOException {
		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 = new HashSet<Integer>(to_1.get(fst));
				final HashSet<Integer> snd_to_1 = new HashSet<Integer>(to_1.get(snd));
				
				fst_to_1.remove(snd);
				snd_to_1.remove(fst); 
				
				//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;
	}
	
	public static class Scanner implements Closeable {
		private BufferedReader br;
		private StringTokenizer tok;
 
		public Scanner(InputStream is) throws IOException {
			br = new BufferedReader(new InputStreamReader(is));
		}	
 
		private void getLine() throws IOException {
			while (!hasNext()) {
				tok = new StringTokenizer(br.readLine());
			}
		}
 
		private boolean hasNext() {
			return tok != null && tok.hasMoreTokens();
		}
 
		public String next() throws IOException {
			getLine();
			return tok.nextToken();
		}
 
		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}
 
		public long nextLong() throws IOException {
			return Long.parseLong(next());
		}
 
		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}
 
		public void close() throws IOException {
			br.close();
		}
	}
}
0