結果
問題 | No.2319 Friends+ |
ユーザー | viral8 |
提出日時 | 2023-05-27 15:30:08 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 906 ms / 3,000 ms |
コード長 | 9,546 bytes |
コンパイル時間 | 2,699 ms |
コンパイル使用メモリ | 89,516 KB |
実行使用メモリ | 210,940 KB |
最終ジャッジ日時 | 2024-06-07 17:07:58 |
合計ジャッジ時間 | 34,795 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 55 ms
36,724 KB |
testcase_01 | AC | 56 ms
37,468 KB |
testcase_02 | AC | 655 ms
188,516 KB |
testcase_03 | AC | 613 ms
197,556 KB |
testcase_04 | AC | 662 ms
197,720 KB |
testcase_05 | AC | 666 ms
197,928 KB |
testcase_06 | AC | 791 ms
199,784 KB |
testcase_07 | AC | 862 ms
199,332 KB |
testcase_08 | AC | 885 ms
188,288 KB |
testcase_09 | AC | 906 ms
198,232 KB |
testcase_10 | AC | 882 ms
199,192 KB |
testcase_11 | AC | 833 ms
199,608 KB |
testcase_12 | AC | 59 ms
37,188 KB |
testcase_13 | AC | 65 ms
37,068 KB |
testcase_14 | AC | 59 ms
37,088 KB |
testcase_15 | AC | 59 ms
37,240 KB |
testcase_16 | AC | 58 ms
37,112 KB |
testcase_17 | AC | 54 ms
36,944 KB |
testcase_18 | AC | 645 ms
198,136 KB |
testcase_19 | AC | 770 ms
198,348 KB |
testcase_20 | AC | 663 ms
200,132 KB |
testcase_21 | AC | 664 ms
201,920 KB |
testcase_22 | AC | 667 ms
198,560 KB |
testcase_23 | AC | 808 ms
210,780 KB |
testcase_24 | AC | 680 ms
199,888 KB |
testcase_25 | AC | 700 ms
199,852 KB |
testcase_26 | AC | 680 ms
198,380 KB |
testcase_27 | AC | 732 ms
210,940 KB |
testcase_28 | AC | 670 ms
200,152 KB |
testcase_29 | AC | 670 ms
198,736 KB |
testcase_30 | AC | 663 ms
199,868 KB |
testcase_31 | AC | 655 ms
198,552 KB |
testcase_32 | AC | 661 ms
200,036 KB |
testcase_33 | AC | 711 ms
198,496 KB |
testcase_34 | AC | 662 ms
199,864 KB |
testcase_35 | AC | 657 ms
198,464 KB |
testcase_36 | AC | 803 ms
210,488 KB |
testcase_37 | AC | 575 ms
199,024 KB |
testcase_38 | AC | 543 ms
197,528 KB |
testcase_39 | AC | 541 ms
198,656 KB |
testcase_40 | AC | 544 ms
191,044 KB |
testcase_41 | AC | 547 ms
198,860 KB |
testcase_42 | AC | 524 ms
197,596 KB |
testcase_43 | AC | 538 ms
197,388 KB |
testcase_44 | AC | 598 ms
209,600 KB |
testcase_45 | AC | 599 ms
199,624 KB |
testcase_46 | AC | 610 ms
199,664 KB |
ソースコード
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.awt.Dimension; import java.util.*; import java.util.stream.*; import java.util.function.*; 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(); BitSet[] world = new BitSet[N+1]; for(int i=1;i<=N;i++) world[i] = new BitSet(N+1); int[] P = new int[N+1]; for(int i=1;i<=N;i++) world[P[i]=sc.nextInt()].set(i); BitSet[] friend = new BitSet[N+1]; for(int i=1;i<=N;i++) friend[i] = new BitSet(N+1); while(M-->0){ int A = sc.nextInt(); int B = sc.nextInt(); friend[A].set(B); friend[B].set(A); } int Q = sc.nextInt(); while(Q-->0){ int X = sc.nextInt(); int Y = sc.nextInt(); BitSet set = (BitSet)friend[X].clone(); set.and(world[P[Y]]); if(P[X]!=P[Y]&&set.cardinality()>0){ world[P[X]].clear(X); world[P[Y]].set(X); P[X] = P[Y]; out.println("Yes"); } else out.println("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 Point nextPoint () { return new Point( nextInt(), nextInt() ); } public Point[] nextPoint ( int n ) { Point[] ans = new Point[n]; for ( int i = 0; i < n; ++i ) { ans[i] = nextPoint(); } 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 ); } } }