結果

問題 No.408 五輪ピック
ユーザー uafr_csuafr_cs
提出日時 2016-08-05 23:19:22
言語 Java21
(openjdk 21)
結果
AC  
実行時間 830 ms / 5,000 ms
コード長 2,678 bytes
コンパイル時間 2,198 ms
コンパイル使用メモリ 78,848 KB
実行使用メモリ 60,420 KB
最終ジャッジ日時 2024-04-24 17:04:01
合計ジャッジ時間 11,719 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 45 ms
36,724 KB
testcase_01 AC 48 ms
37,180 KB
testcase_02 AC 46 ms
36,912 KB
testcase_03 AC 44 ms
37,072 KB
testcase_04 AC 46 ms
37,312 KB
testcase_05 AC 261 ms
50,936 KB
testcase_06 AC 281 ms
52,540 KB
testcase_07 AC 264 ms
52,112 KB
testcase_08 AC 243 ms
49,088 KB
testcase_09 AC 247 ms
50,024 KB
testcase_10 AC 280 ms
52,372 KB
testcase_11 AC 275 ms
50,552 KB
testcase_12 AC 349 ms
53,276 KB
testcase_13 AC 273 ms
52,288 KB
testcase_14 AC 201 ms
47,444 KB
testcase_15 AC 279 ms
50,696 KB
testcase_16 AC 289 ms
50,800 KB
testcase_17 AC 306 ms
50,936 KB
testcase_18 AC 315 ms
52,260 KB
testcase_19 AC 303 ms
52,048 KB
testcase_20 AC 223 ms
49,624 KB
testcase_21 AC 173 ms
45,772 KB
testcase_22 AC 270 ms
52,136 KB
testcase_23 AC 357 ms
60,276 KB
testcase_24 AC 350 ms
60,420 KB
testcase_25 AC 492 ms
56,236 KB
testcase_26 AC 426 ms
59,172 KB
testcase_27 AC 830 ms
57,480 KB
testcase_28 AC 239 ms
51,596 KB
testcase_29 AC 222 ms
52,312 KB
testcase_30 AC 47 ms
36,984 KB
testcase_31 AC 49 ms
36,732 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;
				}else if(fst_to_1.size() > 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