結果

問題 No.408 五輪ピック
ユーザー uafr_csuafr_cs
提出日時 2016-08-05 23:13:21
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 2,475 bytes
コンパイル時間 2,605 ms
コンパイル使用メモリ 80,520 KB
実行使用メモリ 58,592 KB
最終ジャッジ日時 2024-04-24 16:33:04
合計ジャッジ時間 9,879 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 51 ms
36,972 KB
testcase_01 AC 48 ms
36,776 KB
testcase_02 AC 49 ms
36,740 KB
testcase_03 AC 52 ms
36,484 KB
testcase_04 AC 45 ms
36,992 KB
testcase_05 AC 263 ms
50,500 KB
testcase_06 AC 222 ms
51,408 KB
testcase_07 AC 258 ms
49,676 KB
testcase_08 AC 235 ms
49,368 KB
testcase_09 AC 231 ms
49,772 KB
testcase_10 AC 224 ms
48,244 KB
testcase_11 AC 225 ms
50,052 KB
testcase_12 AC 296 ms
51,540 KB
testcase_13 AC 269 ms
50,240 KB
testcase_14 AC 155 ms
45,964 KB
testcase_15 AC 277 ms
51,124 KB
testcase_16 AC 285 ms
50,364 KB
testcase_17 AC 299 ms
50,656 KB
testcase_18 AC 302 ms
50,780 KB
testcase_19 AC 309 ms
52,164 KB
testcase_20 AC 183 ms
46,632 KB
testcase_21 AC 160 ms
45,320 KB
testcase_22 AC 228 ms
51,008 KB
testcase_23 AC 346 ms
58,592 KB
testcase_24 WA -
testcase_25 AC 260 ms
49,900 KB
testcase_26 AC 331 ms
54,924 KB
testcase_27 AC 277 ms
50,360 KB
testcase_28 AC 227 ms
49,424 KB
testcase_29 AC 222 ms
50,040 KB
testcase_30 WA -
testcase_31 WA -
権限があれば一括ダウンロードができます

ソースコード

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 = 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;
	}
	
	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