結果

問題 No.2319 Friends+
ユーザー 👑 tatyamtatyam
提出日時 2023-03-15 02:29:26
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 314 ms / 3,000 ms
コード長 968 bytes
コンパイル時間 1,305 ms
コンパイル使用メモリ 96,740 KB
実行使用メモリ 101,192 KB
最終ジャッジ日時 2023-10-18 13:25:37
合計ジャッジ時間 12,748 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 151 ms
101,092 KB
testcase_03 AC 150 ms
101,092 KB
testcase_04 AC 148 ms
101,092 KB
testcase_05 AC 146 ms
101,092 KB
testcase_06 AC 148 ms
101,092 KB
testcase_07 AC 309 ms
101,092 KB
testcase_08 AC 314 ms
101,092 KB
testcase_09 AC 309 ms
101,092 KB
testcase_10 AC 313 ms
101,092 KB
testcase_11 AC 311 ms
101,092 KB
testcase_12 AC 3 ms
4,792 KB
testcase_13 AC 3 ms
4,792 KB
testcase_14 AC 4 ms
4,792 KB
testcase_15 AC 4 ms
4,792 KB
testcase_16 AC 4 ms
4,792 KB
testcase_17 AC 2 ms
4,348 KB
testcase_18 AC 173 ms
101,092 KB
testcase_19 AC 210 ms
101,092 KB
testcase_20 AC 165 ms
101,092 KB
testcase_21 AC 165 ms
101,092 KB
testcase_22 AC 165 ms
101,092 KB
testcase_23 AC 195 ms
101,092 KB
testcase_24 AC 187 ms
101,092 KB
testcase_25 AC 176 ms
101,092 KB
testcase_26 AC 180 ms
101,092 KB
testcase_27 AC 172 ms
101,092 KB
testcase_28 AC 168 ms
101,092 KB
testcase_29 AC 171 ms
101,092 KB
testcase_30 AC 167 ms
101,092 KB
testcase_31 AC 179 ms
101,092 KB
testcase_32 AC 179 ms
101,092 KB
testcase_33 AC 163 ms
101,092 KB
testcase_34 AC 161 ms
101,092 KB
testcase_35 AC 157 ms
101,092 KB
testcase_36 AC 215 ms
101,092 KB
testcase_37 AC 122 ms
101,092 KB
testcase_38 AC 147 ms
101,092 KB
testcase_39 AC 146 ms
101,092 KB
testcase_40 AC 148 ms
101,092 KB
testcase_41 AC 149 ms
101,192 KB
testcase_42 AC 149 ms
101,092 KB
testcase_43 AC 151 ms
101,092 KB
testcase_44 AC 148 ms
101,092 KB
testcase_45 AC 138 ms
101,092 KB
testcase_46 AC 127 ms
101,092 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC target("avx2")
#pragma GCC optimize("Ofast,unroll-loops")
#include <bitset>
#include <iostream>
#include <vector>
using namespace std;

constexpr int N_MAX = 20032;
int main() {
    cin.tie(0)->sync_with_stdio(0);
    
    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