結果

問題 No.2319 Friends+
ユーザー viral8viral8
提出日時 2023-05-27 14:08:40
言語 Java21
(openjdk 21)
結果
TLE  
実行時間 -
コード長 9,145 bytes
コンパイル時間 2,596 ms
コンパイル使用メモリ 79,376 KB
実行使用メモリ 118,892 KB
最終ジャッジ日時 2023-08-26 21:02:36
合計ジャッジ時間 17,342 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
49,748 KB
testcase_01 AC 38 ms
33,348 KB
testcase_02 AC 687 ms
106,552 KB
testcase_03 AC 525 ms
105,560 KB
testcase_04 AC 535 ms
105,788 KB
testcase_05 AC 521 ms
105,624 KB
testcase_06 AC 531 ms
103,736 KB
testcase_07 AC 794 ms
113,056 KB
testcase_08 AC 701 ms
111,084 KB
testcase_09 AC 723 ms
112,476 KB
testcase_10 AC 749 ms
112,112 KB
testcase_11 AC 669 ms
106,468 KB
testcase_12 AC 46 ms
43,356 KB
testcase_13 AC 43 ms
33,400 KB
testcase_14 AC 43 ms
33,488 KB
testcase_15 AC 43 ms
33,408 KB
testcase_16 AC 43 ms
33,548 KB
testcase_17 AC 38 ms
33,384 KB
testcase_18 TLE -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
testcase_44 -- -
testcase_45 -- -
testcase_46 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.InputStream;
import java.io.PrintStream;
import java.io.PrintWriter;
import java.io.IOException;
import java.math.BigInteger;
import java.awt.Point;
import java.util.*;

public final class Main {

	private static final boolean autoFlush = false;
	private static final SimpleScanner sc = new SimpleScanner( System.in );
	private static final SimplePrinter out = new SimplePrinter( System.out, autoFlush );

	public static void main(String[] args){

		int N = sc.nextInt();
		int M = sc.nextInt();
		int[] P = sc.nextInt(N);
		BitSet[] isFriend = new BitSet[N];
		for(int i=0;i<N;i++)
			isFriend[i] = new BitSet(N);
		while(M-->0){
			int A = sc.nextInt()-1;
			int B = sc.nextInt()-1;
			isFriend[A].set(B);
			isFriend[B].set(A);
		}
		int Q = sc.nextInt();
		while(Q-->0){
			int X = sc.nextInt()-1;
			int Y = sc.nextInt()-1;
			if(P[X]==P[Y]){
				out.println("No");
				continue;
			}
			boolean flag = false;
			int index = 0;
			while((index=isFriend[X].nextSetBit(index))!=-1){
				if(P[index]==P[Y]){
					P[X] = P[Y];
					flag = true;
					break;
				}
				index++;
			}
			out.println(flag?"Yes":"No");
		}

		out.close();
	}
}
/*


             / ̄\
            |     |
             \_/
               |
          /  ̄   ̄  \
        /    \  /    \
     /      ⌒    ⌒      \      よくぞこの提出結果を開いてくれた
     |      (__人__)      |      褒美としてオプーナを買う権利をやる
     \       `⌒´       /   ☆
      /ヽ、--ー、__, -‐ ´  \─/
    / >     ヽ▼●▼<\       ||ー、.
   /ヽ、    \ i |。| |/  ヽ (ニ、`ヽ.
  l    ヽ     l |。| | r-、y `ニ  ノ \
  l     |     |ー─ |  ̄ l   `~ヽ_ノ__
      / ̄ ̄ ̄ ̄ヽ-'ヽ--'  / オープナ  /|
     | ̄ ̄ ̄ ̄ ̄ ̄|/|    | ̄ ̄ ̄ ̄ ̄ ̄|/| ______
 / ̄オプーナ/| ̄|__」/_オープナ /| ̄|__,」__      /|
| ̄ ̄ ̄ ̄ ̄|/オープナ ̄/ ̄ ̄ ̄ ̄|/オプーナ /|   /  |
| ̄ ̄ ̄ ̄ ̄| ̄ ̄ ̄ ̄ ̄|/l ̄ ̄ ̄ ̄| ̄ ̄ ̄ ̄ ̄|/| /
| ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄|
*/

/*////////////////////////////////////////////////
	* My Library *

	@author viral
*/////////////////////////////////////////////////
// MyScanner
final class SimpleScanner {
	final private int buff_size = 1 << 12;
	private final InputStream is;
	private final byte[] buff;
	private int point, length;

	public SimpleScanner ( InputStream is ) {
		this.is = is;
		buff = new byte[buff_size];
		point = length = 0;
	}

	private void reload () {
		do {
			try {
				length = is.read( buff, point = 0, buff_size );
			} catch ( IOException e ) {
				e.printStackTrace();
				System.exit( 1 );
			}
		} while ( length == -1 );
	}

	private byte read () {
		if ( point == length ) {
			reload();
		}
		return buff[point++];
	}

	public byte nextByte () {
		byte c = read();
		while ( c <= ' ' ) {
			c = read();
		}
		return c;
	}

	public int nextInt () {
		int ans = 0;
		byte c = read();
		while ( c <= ' ' ) {
			c = read();
		}
		boolean negate = c == '-';
		if ( c == '-' ) {
			c = read();
		}
		while ( '0' <= c && c <= '9' ) {
			ans = ans * 10 + c - '0';
			c = read();
		}
		return negate ? -ans : ans;
	}

	public long nextLong () {
		long ans = 0;
		byte c = read();
		while ( c <= ' ' ) {
			c = read();
		}
		boolean negate = c == '-';
		if ( c == '-' ) {
			c = read();
		}
		while ( '0' <= c && c <= '9' ) {
			ans = ans * 10 + c - '0';
			c = read();
		}
		return negate ? -ans : ans;
	}

	public char nextChar () {
		byte c = read();
		while ( c <= ' ' ) {
			c = read();
		}
		return ( char )c;
	}

	public String next () {
		StringBuilder ans = new StringBuilder();
		byte c = read();
		while ( c <= ' ' ) {
			c = read();
		}
		while ( c > ' ' ) {
			ans.append( ( char )c );
			c = read();
		}
		return ans.toString();
	}

	public byte[] nextByte ( int n ) {
		byte[] ans = new byte[n];
		for ( int i = 0; i < n; ++i ) {
			ans[i] = nextByte();
		}
		return ans;
	}

	public int[] nextInt ( int n ) {
		int[] ans = new int[n];
		for ( int i = 0; i < n; ++i ) {
			ans[i] = nextInt();
		}
		return ans;
	}

	public long[] nextLong ( int n ) {
		long[] ans = new long[n];
		for ( int i = 0; i < n; ++i ) {
			ans[i] = nextLong();
		}
		return ans;
	}

	public String[] next ( int n ) {
		String[] ans = new String[n];
		for ( int i = 0; i < n; ++i ) {
			ans[i] = next();
		}
		return ans;
	}

	public byte[][] nextByte ( int n, int m ) {
		byte[][] ans = new byte[n][];
		for ( int i = 0; i < n; ++i ) {
			ans[i] = nextByte( m );
		}
		return ans;
	}

	public int[][] nextInt ( int n, int m ) {
		int[][] ans = new int[n][];
		for ( int i = 0; i < n; ++i ) {
			ans[i] = nextInt( m );
		}
		return ans;
	}

	public long[][] nextLong ( int n, int m ) {
		long[][] ans = new long[n][];
		for ( int i = 0; i < n; ++i ) {
			ans[i] = nextLong( m );
		}
		return ans;
	}

	public String[][] next ( int n, int m ) {
		String[][] ans = new String[n][];
		for ( int i = 0; i < n; ++i ) {
			ans[i] = next( m );
		}
		return ans;
	}

	public char[] nextCharArray () {
		return next().toCharArray();
	}

	public char[][] nextCharArray ( int n ) {
		char[][] ans = new char[n][];
		for ( int i = 0; i < n; ++i ) {
			ans[i] = nextCharArray();
		}
		return ans;
	}

	public int[][] nextGraph ( int N, int M ) {
		if ( M == 0 ) {
			return new int[N + 1][0];
		}
		int[][] ans = new int[N + 1][];
		int[] count = new int[N + 1];
		int[][] path = nextInt( M, 2 );
		for ( int[] temp: path ) {
			++count[temp[0]];
			++count[temp[1]];
		}
		for ( int i = 1; i <= N; ++i ) {
			ans[i] = new int[count[i]];
		}
		for ( int[] temp: path ) {
			ans[temp[0]][--count[temp[0]]] = temp[1];
			ans[temp[1]][--count[temp[1]]] = temp[0];
		}
		ans[0] = new int[0];
		return ans;
	}

	public void close () {
		try {
			is.close();
		} catch ( IOException e ) {
			e.printStackTrace();
			System.exit( 1 );
		}
	}
}

// MyPrinter
final class SimplePrinter extends PrintWriter {
	public SimplePrinter ( PrintStream os ) {
		super( os );
	}

	public SimplePrinter ( PrintStream os, boolean bool ) {
		super( os, bool );
	}

	public void println ( int[] array ) {
		println( array, ' ' );
	}

	public void println ( int[] array, String str ) {
		print( array[0] );
		for ( int i = 1; i < array.length; ++i ) {
			print( str );
			print( array[i] );
		}
		println();
	}

	public void println ( int[] array, char c ) {
		print( array[0] );
		for ( int i = 1; i < array.length; ++i ) {
			print( c );
			print( array[i] );
		}
		println();
	}

	public void println ( int[][] array ) {
		println( array, ' ' );
	}

	public void println ( int[][] arrays, String str ) {
		for ( int[] array: arrays ) {
			println( array, str );
		}
	}

	public void println ( int[][] arrays, char c ) {
		for ( int[] array: arrays ) {
			println( array, c );
		}
	}

	public void println ( long[] array ) {
		println( array, ' ' );
	}

	public void println ( long[] array, String str ) {
		print( array[0] );
		for ( int i = 1; i < array.length; ++i ) {
			print( str );
			print( array[i] );
		}
		println();
	}

	public void println ( long[] array, char c ) {
		print( array[0] );
		for ( int i = 1; i < array.length; ++i ) {
			print( c );
			print( array[i] );
		}
		println();
	}

	public void println ( long[][] array ) {
		println( array, ' ' );
	}

	public void println ( long[][] arrays, String str ) {
		for ( long[] array: arrays ) {
			println( array, str );
		}
	}

	public void println ( long[][] arrays, char c ) {
		for ( long[] array: arrays ) {
			println( array, c );
		}
	}

	public void println ( char[] cs, String str ) {
		print( cs[0] );
		for ( int i = 1; i < cs.length; ++i ) {
			print( str );
			print( cs[i] );
		}
		println();
	}

	public void println ( char[] cs, char c ) {
		print( cs[0] );
		for ( int i = 1; i < cs.length; ++i ) {
			print( c );
			print( cs[i] );
		}
		println();
	}

	public void println ( char[][] cs ) {
		for ( char[] c: cs ) {
			println( c );
		}
	}

	public void println ( char[][] cs, String str ) {
		print( cs[0] );
		for ( int i = 1; i < cs.length; ++i ) {
			print( str );
			print( cs[i] );
		}
		println();
	}

	public void println ( char[][] cs, char c ) {
		print( cs[0] );
		for ( int i = 1; i < cs.length; ++i ) {
			print( c );
			print( cs[i] );
		}
		println();
	}

	public <E> void println ( E[] array ) {
		println( array, ' ' );
	}

	public <E> void println ( E[] array, String str ) {
		print( array[0] );
		for ( int i = 1; i < array.length; ++i ) {
			print( str );
			print( array[i] );
		}
		println();
	}

	public <E> void println ( E[] array, char c ) {
		print( array[0] );
		for ( int i = 1; i < array.length; ++i ) {
			print( c );
			print( array[i] );
		}
		println();
	}

	public <E> void println ( E[][] arrays ) {
		println( arrays, ' ' );
	}

	public <E> void println ( E[][] arrays, String str ) {
		for ( E[] array: arrays ) {
			println( array, str );
		}
	}

	public <E> void println ( E[][] arrays, char c ) {
		for ( E[] array: arrays ) {
			println( array, c );
		}
	}
}
0