結果

問題 No.2319 Friends+
ユーザー SSRSSSRS
提出日時 2023-05-26 22:36:48
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 693 ms / 3,000 ms
コード長 775 bytes
コンパイル時間 1,526 ms
コンパイル使用メモリ 169,916 KB
実行使用メモリ 102,900 KB
最終ジャッジ日時 2023-08-26 12:45:37
合計ジャッジ時間 26,540 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 513 ms
102,716 KB
testcase_03 AC 498 ms
102,428 KB
testcase_04 AC 505 ms
102,680 KB
testcase_05 AC 499 ms
102,564 KB
testcase_06 AC 499 ms
102,592 KB
testcase_07 AC 667 ms
102,588 KB
testcase_08 AC 693 ms
102,588 KB
testcase_09 AC 685 ms
102,616 KB
testcase_10 AC 667 ms
102,900 KB
testcase_11 AC 671 ms
102,612 KB
testcase_12 AC 3 ms
4,728 KB
testcase_13 AC 3 ms
4,604 KB
testcase_14 AC 3 ms
4,592 KB
testcase_15 AC 3 ms
4,608 KB
testcase_16 AC 4 ms
4,756 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 519 ms
102,396 KB
testcase_19 AC 551 ms
102,696 KB
testcase_20 AC 520 ms
102,724 KB
testcase_21 AC 518 ms
102,572 KB
testcase_22 AC 531 ms
102,628 KB
testcase_23 AC 556 ms
102,712 KB
testcase_24 AC 532 ms
102,864 KB
testcase_25 AC 521 ms
102,732 KB
testcase_26 AC 517 ms
102,532 KB
testcase_27 AC 524 ms
102,668 KB
testcase_28 AC 504 ms
102,696 KB
testcase_29 AC 508 ms
102,564 KB
testcase_30 AC 517 ms
102,860 KB
testcase_31 AC 500 ms
102,528 KB
testcase_32 AC 508 ms
102,720 KB
testcase_33 AC 514 ms
102,720 KB
testcase_34 AC 509 ms
102,564 KB
testcase_35 AC 503 ms
102,588 KB
testcase_36 AC 589 ms
102,532 KB
testcase_37 AC 496 ms
102,636 KB
testcase_38 AC 502 ms
102,416 KB
testcase_39 AC 504 ms
102,528 KB
testcase_40 AC 516 ms
102,740 KB
testcase_41 AC 501 ms
102,496 KB
testcase_42 AC 523 ms
102,560 KB
testcase_43 AC 504 ms
102,564 KB
testcase_44 AC 529 ms
102,532 KB
testcase_45 AC 519 ms
102,680 KB
testcase_46 AC 498 ms
102,524 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
int main(){
  int N, M;
  cin >> N >> M;
  vector<int> P(N);
  for (int i = 0; i < N; i++){
    cin >> P[i];
    P[i]--;
  }
  vector<int> A(M), B(M);
  for (int i = 0; i < M; i++){
    cin >> A[i] >> B[i];
    A[i]--;
    B[i]--;
  }
  vector<bitset<20000>> W(N);
  for (int i = 0; i < N; i++){
    W[P[i]].set(i);
  }
  vector<bitset<20000>> F(N);
  for (int i = 0; i < M; i++){
    F[A[i]].set(B[i]);
    F[B[i]].set(A[i]);
  }
  int Q;
  cin >> Q;
  for (int i = 0; i < Q; i++){
    int X, Y;
    cin >> X >> Y;
    X--;
    Y--;
    if (P[X] != P[Y] && (W[P[Y]] & F[X]).any()){
      cout << "Yes" << endl;
      W[P[X]].reset(X);
      P[X] = P[Y];
      W[P[X]].set(X);
    } else {
      cout << "No" << endl;
    }
  }
}
0