結果

問題 No.2319 Friends+
ユーザー GEX777GEX777
提出日時 2023-05-27 14:11:27
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 755 ms / 3,000 ms
コード長 3,124 bytes
コンパイル時間 1,760 ms
コンパイル使用メモリ 133,056 KB
実行使用メモリ 107,452 KB
最終ジャッジ日時 2023-08-26 21:04:43
合計ジャッジ時間 29,788 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 591 ms
107,380 KB
testcase_03 AC 544 ms
107,172 KB
testcase_04 AC 538 ms
107,344 KB
testcase_05 AC 539 ms
107,324 KB
testcase_06 AC 545 ms
107,196 KB
testcase_07 AC 750 ms
107,084 KB
testcase_08 AC 754 ms
107,156 KB
testcase_09 AC 755 ms
107,160 KB
testcase_10 AC 749 ms
107,260 KB
testcase_11 AC 737 ms
107,164 KB
testcase_12 AC 4 ms
4,680 KB
testcase_13 AC 4 ms
4,620 KB
testcase_14 AC 4 ms
4,700 KB
testcase_15 AC 3 ms
4,648 KB
testcase_16 AC 4 ms
4,852 KB
testcase_17 AC 2 ms
4,384 KB
testcase_18 AC 599 ms
107,204 KB
testcase_19 AC 630 ms
107,200 KB
testcase_20 AC 568 ms
107,156 KB
testcase_21 AC 564 ms
107,104 KB
testcase_22 AC 567 ms
107,276 KB
testcase_23 AC 594 ms
107,152 KB
testcase_24 AC 592 ms
107,100 KB
testcase_25 AC 592 ms
107,232 KB
testcase_26 AC 581 ms
107,208 KB
testcase_27 AC 591 ms
107,288 KB
testcase_28 AC 576 ms
107,184 KB
testcase_29 AC 572 ms
107,260 KB
testcase_30 AC 572 ms
107,452 KB
testcase_31 AC 572 ms
107,188 KB
testcase_32 AC 563 ms
107,104 KB
testcase_33 AC 560 ms
107,016 KB
testcase_34 AC 566 ms
107,204 KB
testcase_35 AC 563 ms
107,108 KB
testcase_36 AC 643 ms
107,152 KB
testcase_37 AC 514 ms
107,156 KB
testcase_38 AC 552 ms
107,412 KB
testcase_39 AC 549 ms
107,072 KB
testcase_40 AC 565 ms
107,276 KB
testcase_41 AC 556 ms
107,284 KB
testcase_42 AC 554 ms
107,148 KB
testcase_43 AC 549 ms
107,084 KB
testcase_44 AC 551 ms
107,056 KB
testcase_45 AC 538 ms
107,232 KB
testcase_46 AC 525 ms
107,148 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

/**
 * @file main.cpp
 * @brief 競技プログラミングのデッキ
 * @author Gex777
 * @date update:2023/04/21
 * @details boost
 */

#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <cmath>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <string>
#include <sstream>
#include <climits>
#include <bitset>
#include <deque>
#include <cassert>
#include <list>
#include <queue>
#include <valarray>
#include <complex>
#include <bitset>

// #include <atcoder/all> //ACL(環境依存)
// #include <boost/multiprecision/cpp_int.hpp>

using namespace std;
// using namespace atcoder;
// namespace mp = boost::multiprecision;
// using Bint = mp::cpp_int;

// 独自型定義
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<vvll> vvvll;
typedef vector<string> vs;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
using AdjacencyList = map<int, vi>;
using EdgeAdjacencyList = map<int, vector<int, int>>;

// マクロの宣言
#define all(x) x.begin(), x.end()

// 定数宣言
constexpr double PI = 3.141592653589793;
constexpr ll MOD998 = 998244353;
constexpr ll MOD107 = 1'000'000'007;

// コンテナの中身を表示, 1行で出力をする, debug用
template <typename T>
void printv(T &a)
{
    for (const auto &x : a)
    {
        cout << x << " ";
    }
    puts("");
    return;
}

// コンテナの中身を表示, 改行して出力をする, debug用
template <typename T>
void println(T &a)
{
    for (const auto &x : a)
    {
        cout << x << endl;
    }
    return;
}

/*##############################################
################################################*/

int main()
{
    int N, M;
    cin >> N >> M;

    constexpr int BNUM = 20000;
    vector<bitset<BNUM>> Friend(N); // i番目の人とj番目の人はフレンドか
    vector<bitset<BNUM>> world(N);  // world[i]にj番目の人がいるか
    vector<int> pos(N);             // i番目の人が今いるワールドの番号

    for (int i = 0; i < N; ++i)
    {
        int p;
        cin >> p;
        p--;
        world[p].set(i);
        pos[i] = p;
    }

    for (int i = 0; i < M; ++i)
    {
        int A, B;
        cin >> A >> B;
        --A;
        --B;
        Friend[A].set(B);
        Friend[B].set(A);
    }

    int Q;
    cin >> Q;
    vs ans(Q, "No");

    for (int i = 0; i < Q; ++i)
    {
        int X, Y;
        cin >> X >> Y;
        --X;
        --Y;

        if ((pos[X] != pos[Y]) && (Friend[X]&world[pos[Y]]).any()) // XのフレンドがとYのいるワールドもいる
        {
            world[pos[X]].reset(X);
            world[pos[Y]].set(X);
            pos[X] = pos[Y];
            ans[i] = "Yes";
        }
        // cout << "pos=";
        // printv(pos);
    }

    println(ans); // クエリの結果を出力
}
0