結果

問題 No.2319 Friends+
ユーザー srjywrdnprktsrjywrdnprkt
提出日時 2023-06-30 01:26:59
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,636 bytes
コンパイル時間 4,125 ms
コンパイル使用メモリ 205,552 KB
実行使用メモリ 56,320 KB
最終ジャッジ日時 2023-09-20 20:13:19
合計ジャッジ時間 35,540 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 AC 547 ms
56,120 KB
testcase_05 WA -
testcase_06 AC 544 ms
56,056 KB
testcase_07 AC 504 ms
7,196 KB
testcase_08 AC 506 ms
7,104 KB
testcase_09 AC 510 ms
6,892 KB
testcase_10 AC 508 ms
6,992 KB
testcase_11 AC 505 ms
6,896 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 3 ms
4,380 KB
testcase_15 AC 3 ms
4,376 KB
testcase_16 AC 3 ms
4,376 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 WA -
testcase_19 AC 474 ms
6,996 KB
testcase_20 AC 508 ms
6,996 KB
testcase_21 AC 483 ms
7,012 KB
testcase_22 AC 530 ms
7,084 KB
testcase_23 AC 463 ms
6,896 KB
testcase_24 AC 468 ms
6,908 KB
testcase_25 AC 463 ms
6,896 KB
testcase_26 AC 468 ms
7,064 KB
testcase_27 AC 465 ms
7,128 KB
testcase_28 AC 685 ms
6,908 KB
testcase_29 AC 581 ms
7,064 KB
testcase_30 AC 569 ms
6,944 KB
testcase_31 AC 498 ms
6,896 KB
testcase_32 AC 500 ms
6,992 KB
testcase_33 AC 481 ms
7,000 KB
testcase_34 AC 481 ms
6,892 KB
testcase_35 AC 474 ms
7,016 KB
testcase_36 AC 498 ms
6,948 KB
testcase_37 AC 774 ms
26,712 KB
testcase_38 AC 474 ms
6,936 KB
testcase_39 AC 480 ms
7,000 KB
testcase_40 AC 482 ms
7,008 KB
testcase_41 AC 489 ms
6,996 KB
testcase_42 AC 498 ms
7,000 KB
testcase_43 AC 514 ms
7,060 KB
testcase_44 AC 558 ms
6,944 KB
testcase_45 AC 777 ms
27,316 KB
testcase_46 AC 483 ms
24,020 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;
using ll = long long;


int main(){

    int N, M, Q, A, B, K;
    cin >> N >> M;
    K = sqrt(M);
    vector<int> P(N), lg;
    vector<bool> large(N);
    for (int i=0; i<N; i++){
        cin >> P[i]; P[i]--;
    }
    vector<vector<int>> E(N);
    for (int i=0; i<M; i++){
        cin >> A >> B; A--; B--;
        E[A].push_back(B);
        E[B].push_back(A);
    }

    vector<vector<int>> cnt(N);

    for (int i=0; i<N; i++){
        if (E[i].size() >= K){
            large[i] = 1;
            lg.push_back(i);
        }
    }
    for (auto i : lg){
        cnt[i].resize(N);
        for (auto x : E[i]){
            if (!large[x]) cnt[i][P[x]]++;
        }
    }

    cin >> Q;
    while(Q){
        Q--;
        bool f=0;
        cin >> A >> B; A--; B--;
        if (P[A] == P[B]){
            cout << "No" << endl;
            continue;
        }
        if (!large[A]){
            for (auto x : E[A]){
                if (P[x] == P[B]) f=1;
            }
            if (f){
                for (auto x : E[A]){
                    if (large[x]){
                        cnt[x][P[A]]--;
                        cnt[x][P[B]]++;
                    }
                }
                P[A] = P[B];
                cout << "Yes" << endl;
            }
            else cout << "No" << endl;
        }
        else{
            for (auto x : lg) if (P[x] == P[B]) f=1;
            if (cnt[A][P[B]] > 0) f=1;
            if (f){
                cout << "Yes" << endl;
                P[A] = P[B];
            }
            else cout << "No" << endl;
        }
    }

    return 0;
}
0