結果

問題 No.2319 Friends+
ユーザー 👑 hitonanodehitonanode
提出日時 2023-05-27 23:18:28
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 353 ms / 3,000 ms
コード長 923 bytes
コンパイル時間 2,819 ms
コンパイル使用メモリ 90,576 KB
実行使用メモリ 101,100 KB
最終ジャッジ日時 2023-08-27 01:08:55
合計ジャッジ時間 13,472 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 195 ms
100,868 KB
testcase_03 AC 175 ms
100,844 KB
testcase_04 AC 170 ms
100,864 KB
testcase_05 AC 170 ms
100,832 KB
testcase_06 AC 173 ms
101,028 KB
testcase_07 AC 344 ms
100,936 KB
testcase_08 AC 344 ms
101,076 KB
testcase_09 AC 344 ms
100,720 KB
testcase_10 AC 353 ms
100,988 KB
testcase_11 AC 343 ms
100,988 KB
testcase_12 AC 3 ms
4,584 KB
testcase_13 AC 3 ms
4,600 KB
testcase_14 AC 3 ms
4,588 KB
testcase_15 AC 3 ms
4,728 KB
testcase_16 AC 3 ms
4,512 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 219 ms
101,028 KB
testcase_19 AC 250 ms
100,928 KB
testcase_20 AC 197 ms
101,036 KB
testcase_21 AC 196 ms
101,028 KB
testcase_22 AC 198 ms
100,716 KB
testcase_23 AC 236 ms
100,988 KB
testcase_24 AC 211 ms
100,812 KB
testcase_25 AC 219 ms
100,772 KB
testcase_26 AC 204 ms
101,100 KB
testcase_27 AC 204 ms
100,708 KB
testcase_28 AC 200 ms
100,856 KB
testcase_29 AC 196 ms
100,804 KB
testcase_30 AC 196 ms
100,780 KB
testcase_31 AC 196 ms
100,844 KB
testcase_32 AC 196 ms
100,976 KB
testcase_33 AC 195 ms
100,796 KB
testcase_34 AC 192 ms
100,848 KB
testcase_35 AC 185 ms
100,856 KB
testcase_36 AC 247 ms
100,696 KB
testcase_37 AC 146 ms
100,764 KB
testcase_38 AC 168 ms
100,848 KB
testcase_39 AC 167 ms
100,700 KB
testcase_40 AC 170 ms
101,036 KB
testcase_41 AC 173 ms
100,720 KB
testcase_42 AC 175 ms
100,864 KB
testcase_43 AC 176 ms
100,720 KB
testcase_44 AC 170 ms
100,808 KB
testcase_45 AC 161 ms
100,848 KB
testcase_46 AC 157 ms
100,712 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int main() {
    cin.tie(nullptr), ios::sync_with_stdio(false);
    int N, M;
    cin >> N >> M;
    using BS = bitset<20000>;
    vector<BS> is_friend(N), world_has(N);
    vector<int> P(N);

    for (int i = 0; i < N; ++i) cin >> P.at(i), P.at(i)--, world_has.at(P.at(i)).set(i);

    while (M--) {
        int a, b;
        cin >> a >> b;
        --a, --b;
        is_friend.at(a).set(b);
        is_friend.at(b).set(a);
    }

    int Q;
    cin >> Q;
    while (Q--) {
        int x, y;
        cin >> x >> y;
        --x, --y;
        int j = P.at(y);
        if (P.at(x) != P.at(y) and (world_has.at(P.at(y)) & is_friend.at(x)).any()) {
            puts("Yes");
            world_has.at(P.at(x)).reset(x);
            P.at(x) = P.at(y);
            world_has.at(P.at(x)).set(x);
        } else {
            puts("No");
        }
    }
}
0