結果

問題 No.408 五輪ピック
ユーザー uafr_csuafr_cs
提出日時 2016-08-05 23:34:57
言語 Java19
(openjdk 21)
結果
AC  
実行時間 445 ms / 5,000 ms
コード長 2,878 bytes
コンパイル時間 4,880 ms
コンパイル使用メモリ 74,604 KB
実行使用メモリ 69,092 KB
最終ジャッジ日時 2023-08-07 01:14:38
合計ジャッジ時間 13,970 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 43 ms
49,400 KB
testcase_01 AC 43 ms
49,428 KB
testcase_02 AC 44 ms
49,640 KB
testcase_03 AC 43 ms
49,292 KB
testcase_04 AC 43 ms
49,444 KB
testcase_05 AC 306 ms
61,392 KB
testcase_06 AC 280 ms
64,124 KB
testcase_07 AC 294 ms
63,396 KB
testcase_08 AC 253 ms
60,088 KB
testcase_09 AC 246 ms
61,876 KB
testcase_10 AC 254 ms
61,856 KB
testcase_11 AC 252 ms
61,524 KB
testcase_12 AC 340 ms
63,716 KB
testcase_13 AC 298 ms
60,420 KB
testcase_14 AC 191 ms
58,912 KB
testcase_15 AC 299 ms
61,464 KB
testcase_16 AC 306 ms
61,344 KB
testcase_17 AC 319 ms
61,804 KB
testcase_18 AC 337 ms
61,732 KB
testcase_19 AC 335 ms
62,044 KB
testcase_20 AC 207 ms
59,552 KB
testcase_21 AC 176 ms
55,600 KB
testcase_22 AC 264 ms
63,804 KB
testcase_23 AC 397 ms
69,092 KB
testcase_24 AC 306 ms
66,960 KB
testcase_25 AC 284 ms
63,196 KB
testcase_26 AC 445 ms
66,648 KB
testcase_27 AC 343 ms
68,060 KB
testcase_28 AC 234 ms
62,200 KB
testcase_29 AC 230 ms
61,372 KB
testcase_30 AC 43 ms
49,424 KB
testcase_31 AC 43 ms
49,640 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 int fst_size = to_1.get(fst).size() - (to_1.get(fst).contains(snd) ? 1 : 0);
				final int snd_size = to_1.get(snd).size() - (to_1.get(snd).contains(fst) ? 1 : 0);
				
				//System.out.println(fst_to_1 + " " + snd_to_1);
				
				if(fst_size == 0 || snd_size == 0){
					continue;
				}else if(fst_size != snd_size){
					System.out.println("YES");
					return;
				}else if(fst_size >= 2){
					System.out.println("YES");
					return;
				}else{
					
					boolean flg = true;
					for(final int tmp : adj.get(0)){
						if(to_1.get(fst).contains(tmp) && to_1.get(snd).contains(tmp)){
							flg = false;
							break;
						}
					}
					
					if(flg){
						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