結果

問題 No.2319 Friends+
ユーザー 👑 tatyamtatyam
提出日時 2023-03-15 02:23:58
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 762 ms / 3,000 ms
コード長 857 bytes
コンパイル時間 911 ms
コンパイル使用メモリ 90,880 KB
実行使用メモリ 101,312 KB
最終ジャッジ日時 2023-10-18 13:25:23
合計ジャッジ時間 27,965 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 551 ms
101,140 KB
testcase_03 AC 537 ms
101,268 KB
testcase_04 AC 538 ms
101,268 KB
testcase_05 AC 539 ms
101,268 KB
testcase_06 AC 537 ms
101,268 KB
testcase_07 AC 750 ms
101,268 KB
testcase_08 AC 759 ms
101,268 KB
testcase_09 AC 762 ms
101,268 KB
testcase_10 AC 750 ms
101,268 KB
testcase_11 AC 760 ms
101,268 KB
testcase_12 AC 4 ms
4,912 KB
testcase_13 AC 4 ms
4,912 KB
testcase_14 AC 4 ms
4,912 KB
testcase_15 AC 4 ms
4,912 KB
testcase_16 AC 4 ms
4,912 KB
testcase_17 AC 1 ms
4,348 KB
testcase_18 AC 593 ms
101,268 KB
testcase_19 AC 634 ms
101,268 KB
testcase_20 AC 573 ms
101,268 KB
testcase_21 AC 566 ms
101,268 KB
testcase_22 AC 567 ms
101,268 KB
testcase_23 AC 604 ms
101,268 KB
testcase_24 AC 606 ms
101,268 KB
testcase_25 AC 599 ms
101,268 KB
testcase_26 AC 583 ms
101,268 KB
testcase_27 AC 577 ms
101,268 KB
testcase_28 AC 575 ms
101,268 KB
testcase_29 AC 574 ms
101,268 KB
testcase_30 AC 572 ms
101,268 KB
testcase_31 AC 573 ms
101,268 KB
testcase_32 AC 567 ms
101,268 KB
testcase_33 AC 571 ms
101,268 KB
testcase_34 AC 567 ms
101,268 KB
testcase_35 AC 560 ms
101,268 KB
testcase_36 AC 639 ms
101,268 KB
testcase_37 AC 518 ms
101,268 KB
testcase_38 AC 552 ms
101,268 KB
testcase_39 AC 555 ms
101,268 KB
testcase_40 AC 558 ms
101,268 KB
testcase_41 AC 557 ms
101,268 KB
testcase_42 AC 560 ms
101,268 KB
testcase_43 AC 558 ms
101,312 KB
testcase_44 AC 558 ms
101,312 KB
testcase_45 AC 544 ms
101,268 KB
testcase_46 AC 527 ms
101,268 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bitset>
#include <iostream>
#include <vector>
using namespace std;

constexpr int N_MAX = 20032;
int main() {
    int N, M;
    cin >> N >> M;
    vector<int> P(N);
    for(int& p : P) {
        cin >> p;
        p--;
    }
    
    vector<bitset<N_MAX>> room(N), friends(N);
    for(int i = 0; i < N; i++) room[P[i]][i] = 1;
    while(M--) {
        int A, B;
        cin >> A >> B;
        A--; B--;
        friends[A][B] = friends[B][A] = 1;
    }
    
    int Q;
    cin >> Q;
    while(Q--) {
        int X, Y;
        cin >> X >> Y;
        X--; Y--;
        if(P[X] == P[Y]) {
            puts("No");
            continue;
        }
        if((friends[X] & room[P[Y]]).none()) {
            puts("No");
            continue;
        }
        puts("Yes");
        room[P[X]][X] = 0;
        P[X] = P[Y];
        room[P[X]][X] = 1;
    }
}
0