結果

問題 No.2319 Friends+
ユーザー t98slidert98slider
提出日時 2023-05-26 23:18:21
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 252 ms / 3,000 ms
コード長 1,540 bytes
コンパイル時間 1,453 ms
コンパイル使用メモリ 171,376 KB
実行使用メモリ 29,144 KB
最終ジャッジ日時 2023-08-26 13:45:46
合計ジャッジ時間 9,436 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,384 KB
testcase_02 AC 94 ms
7,224 KB
testcase_03 AC 91 ms
7,432 KB
testcase_04 AC 90 ms
7,336 KB
testcase_05 AC 89 ms
7,264 KB
testcase_06 AC 93 ms
7,168 KB
testcase_07 AC 98 ms
7,496 KB
testcase_08 AC 97 ms
7,692 KB
testcase_09 AC 97 ms
7,480 KB
testcase_10 AC 101 ms
7,576 KB
testcase_11 AC 103 ms
7,432 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 1 ms
4,380 KB
testcase_18 AC 84 ms
8,060 KB
testcase_19 AC 82 ms
7,832 KB
testcase_20 AC 84 ms
7,480 KB
testcase_21 AC 84 ms
7,692 KB
testcase_22 AC 90 ms
7,500 KB
testcase_23 AC 83 ms
7,540 KB
testcase_24 AC 80 ms
7,496 KB
testcase_25 AC 80 ms
7,764 KB
testcase_26 AC 81 ms
7,572 KB
testcase_27 AC 129 ms
7,468 KB
testcase_28 AC 108 ms
7,432 KB
testcase_29 AC 96 ms
7,600 KB
testcase_30 AC 95 ms
7,540 KB
testcase_31 AC 88 ms
7,432 KB
testcase_32 AC 88 ms
7,564 KB
testcase_33 AC 84 ms
7,452 KB
testcase_34 AC 87 ms
7,540 KB
testcase_35 AC 85 ms
7,496 KB
testcase_36 AC 77 ms
7,168 KB
testcase_37 AC 248 ms
29,144 KB
testcase_38 AC 84 ms
7,452 KB
testcase_39 AC 89 ms
7,528 KB
testcase_40 AC 86 ms
7,444 KB
testcase_41 AC 87 ms
7,472 KB
testcase_42 AC 85 ms
7,524 KB
testcase_43 AC 93 ms
7,484 KB
testcase_44 AC 96 ms
7,500 KB
testcase_45 AC 90 ms
7,764 KB
testcase_46 AC 252 ms
25,144 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, m, u, v;
    cin >> n >> m;
    int sqN = 640;
    vector<int> pos(n);
    //vector<set<int>> world(n);
    vector<vector<int>> fri(n);
    vector<vector<int>> g(n);
    vector<vector<int>> G(n);
    for(int i = 0; i < n; i++){
        cin >> pos[i];
        pos[i]--;
    }
    for(int i = 0; i < m; i++){
        cin >> u >> v;
        u--, v--;
        g[u].emplace_back(v);
        g[v].emplace_back(u);
    }
    for(int i = 0; i < n; i++){
        if(g[i].size() >= sqN){
            fri[i].resize(n, 0);
        }
    }
    for(int i = 0; i < n; i++){
        for(auto &&j : g[i]){
            if(g[j].size() >= sqN){
                G[i].emplace_back(j);
                fri[j][pos[i]]++;
            }
        }
    }
    int Q;
    cin >> Q;
    while(Q--){
        cin >> u >> v;
        u--, v--;
        if(pos[u] == pos[v]){
            cout << "No" << '\n';
            continue;
        }
        bool flag = false;
        if(g[u].size() < sqN){
            for(auto &&c : g[u]){
                if(pos[c] == pos[v]){
                    flag = true;
                    break;
                }
            }
        }else{
            flag = fri[u][pos[v]] >= 1;
        }
        cout << (flag ? "Yes" : "No") << '\n';
        if(!flag) continue;
        for(auto &&c : G[u]){
            fri[c][pos[u]]--;
            fri[c][pos[v]]++;
        }
        pos[u] = pos[v];
    }
}
0