結果

問題 No.2319 Friends+
ユーザー maguroflymagurofly
提出日時 2023-05-27 14:01:07
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 716 ms / 3,000 ms
コード長 806 bytes
コンパイル時間 2,172 ms
コンパイル使用メモリ 202,460 KB
実行使用メモリ 101,112 KB
最終ジャッジ日時 2023-08-26 20:59:38
合計ジャッジ時間 29,088 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 501 ms
100,812 KB
testcase_03 AC 519 ms
100,800 KB
testcase_04 AC 488 ms
100,868 KB
testcase_05 AC 479 ms
101,056 KB
testcase_06 AC 483 ms
100,936 KB
testcase_07 AC 660 ms
100,736 KB
testcase_08 AC 670 ms
101,112 KB
testcase_09 AC 715 ms
100,932 KB
testcase_10 AC 716 ms
100,732 KB
testcase_11 AC 672 ms
100,736 KB
testcase_12 AC 4 ms
4,740 KB
testcase_13 AC 3 ms
4,692 KB
testcase_14 AC 4 ms
4,544 KB
testcase_15 AC 4 ms
4,580 KB
testcase_16 AC 3 ms
4,644 KB
testcase_17 AC 1 ms
4,380 KB
testcase_18 AC 525 ms
100,860 KB
testcase_19 AC 567 ms
100,840 KB
testcase_20 AC 505 ms
101,080 KB
testcase_21 AC 513 ms
100,924 KB
testcase_22 AC 518 ms
100,768 KB
testcase_23 AC 533 ms
100,736 KB
testcase_24 AC 525 ms
100,860 KB
testcase_25 AC 525 ms
100,732 KB
testcase_26 AC 516 ms
100,928 KB
testcase_27 AC 537 ms
100,752 KB
testcase_28 AC 517 ms
100,800 KB
testcase_29 AC 518 ms
100,772 KB
testcase_30 AC 503 ms
100,944 KB
testcase_31 AC 497 ms
100,852 KB
testcase_32 AC 506 ms
100,800 KB
testcase_33 AC 528 ms
100,932 KB
testcase_34 AC 523 ms
100,792 KB
testcase_35 AC 517 ms
100,928 KB
testcase_36 AC 593 ms
100,792 KB
testcase_37 AC 469 ms
100,792 KB
testcase_38 AC 495 ms
101,004 KB
testcase_39 AC 508 ms
101,088 KB
testcase_40 AC 513 ms
100,788 KB
testcase_41 AC 494 ms
101,096 KB
testcase_42 AC 513 ms
101,112 KB
testcase_43 AC 513 ms
100,940 KB
testcase_44 AC 511 ms
100,856 KB
testcase_45 AC 489 ms
100,852 KB
testcase_46 AC 477 ms
100,836 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
const int N_MAX = 20000;
int main() {
  int N, M; cin >> N >> M;
  vector<int> world_of(N);
  vector<bitset<N_MAX>> in_world(N);
  for (int i = 0; i < N; i++) {
    cin >> world_of[i]; world_of[i]--;
    in_world[world_of[i]][i] = true;
  }
  vector<bitset<N_MAX>> friend_of(N);
  for (int i = 0; i < M; i++) {
    int A, B; cin >> A >> B; A--; B--;
    friend_of[A][B] = friend_of[B][A] = true;
  }

  int Q;
  cin >> Q;
  for (int t = 0; t < Q; t++) {
    int X, Y; cin >> X >> Y; X--; Y--;
    if (world_of[X] != world_of[Y] && (friend_of[X] & in_world[world_of[Y]]).any()) {
      cout << "Yes\n";
      in_world[world_of[X]][X] = false;
      world_of[X] = world_of[Y];
      in_world[world_of[X]][X] = true;
    } else {
      cout << "No\n";
    }
  }
}
0