結果

問題 No.2319 Friends+
ユーザー hitonanode
提出日時 2023-05-27 23:18:28
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 446 ms / 3,000 ms
コード長 923 bytes
コンパイル時間 1,023 ms
コンパイル使用メモリ 91,456 KB
実行使用メモリ 101,120 KB
最終ジャッジ日時 2024-12-26 05:32:37
合計ジャッジ時間 15,770 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 45
権限があれば一括ダウンロードができます

ソースコード

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