結果

問題 No.2319 Friends+
ユーザー ぷらぷら
提出日時 2023-07-25 01:13:34
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 526 ms / 3,000 ms
コード長 1,852 bytes
コンパイル時間 2,302 ms
コンパイル使用メモリ 201,512 KB
実行使用メモリ 59,392 KB
最終ジャッジ日時 2024-04-09 20:00:44
合計ジャッジ時間 14,981 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 1 ms
6,944 KB
testcase_02 AC 428 ms
59,264 KB
testcase_03 AC 526 ms
59,392 KB
testcase_04 AC 446 ms
59,392 KB
testcase_05 AC 443 ms
59,264 KB
testcase_06 AC 474 ms
59,264 KB
testcase_07 AC 114 ms
7,680 KB
testcase_08 AC 113 ms
7,680 KB
testcase_09 AC 112 ms
7,808 KB
testcase_10 AC 115 ms
7,552 KB
testcase_11 AC 114 ms
7,680 KB
testcase_12 AC 2 ms
6,944 KB
testcase_13 AC 2 ms
6,940 KB
testcase_14 AC 2 ms
6,944 KB
testcase_15 AC 1 ms
6,940 KB
testcase_16 AC 2 ms
6,940 KB
testcase_17 AC 2 ms
6,940 KB
testcase_18 AC 93 ms
8,192 KB
testcase_19 AC 95 ms
7,936 KB
testcase_20 AC 99 ms
7,680 KB
testcase_21 AC 92 ms
7,680 KB
testcase_22 AC 100 ms
7,552 KB
testcase_23 AC 90 ms
7,808 KB
testcase_24 AC 96 ms
7,936 KB
testcase_25 AC 90 ms
7,808 KB
testcase_26 AC 91 ms
7,680 KB
testcase_27 AC 94 ms
7,808 KB
testcase_28 AC 148 ms
7,680 KB
testcase_29 AC 124 ms
7,552 KB
testcase_30 AC 112 ms
7,680 KB
testcase_31 AC 105 ms
7,680 KB
testcase_32 AC 101 ms
7,680 KB
testcase_33 AC 99 ms
7,680 KB
testcase_34 AC 98 ms
7,680 KB
testcase_35 AC 94 ms
7,552 KB
testcase_36 AC 92 ms
7,680 KB
testcase_37 AC 226 ms
29,440 KB
testcase_38 AC 93 ms
7,808 KB
testcase_39 AC 94 ms
7,552 KB
testcase_40 AC 93 ms
7,808 KB
testcase_41 AC 91 ms
7,680 KB
testcase_42 AC 95 ms
7,552 KB
testcase_43 AC 99 ms
7,680 KB
testcase_44 AC 112 ms
7,936 KB
testcase_45 AC 258 ms
28,288 KB
testcase_46 AC 212 ms
25,472 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N,M;
    cin >> N >> M;
    vector<int>P(N);
    for(int i = 0; i < N; i++) {
        cin >> P[i];
        P[i]--;
    }
    vector<vector<int>>road1(N);
    vector<vector<int>>road2(N);
    for(int i = 0; i < M; i++) {
        int A,B;
        cin >> A >> B;
        A--;
        B--;
        road1[A].push_back(B);
        road1[B].push_back(A);
    }
    int B = 334;
    vector<vector<int>>cnt(N);
    for(int i = 0; i < N; i++) {
        if(road1[i].size() >= B) {
            cnt[i].resize(N);
        }
    }
    for(int i = 0; i < N; i++) {
        for(int j:road1[i]) {
            if(road1[j].size() >= B) {
                road2[i].push_back(j);
                cnt[j][P[i]]++;
            }
        }
    }
    int Q;
    cin >> Q;
    while(Q--) {
        int X,Y;
        cin >> X >> Y;
        X--;
        Y--;
        if(P[X] == P[Y]) {
            cout << "No" << "\n";
            continue;
        }
        if(road1[X].size() >= B) {
            if(cnt[X][P[Y]]) {
                cout << "Yes" << "\n";
                for(int i:road2[X]) {
                    cnt[i][P[X]]--;
                    cnt[i][P[Y]]++;
                }
                P[X] = P[Y];
            }
            else {
                cout << "No" << "\n";
            }
        }
        else {
            bool f = false;
            for(int i:road1[X]) {
                if(P[i] == P[Y]) f = true;
            }
            if(f) {
                cout << "Yes" << "\n";
                for(int i:road2[X]) {
                    cnt[i][P[X]]--;
                    cnt[i][P[Y]]++;
                }
                P[X] = P[Y];
            }
            else {
                cout << "No" << "\n";
            }
        }
    }
}
0