結果

問題 No.2319 Friends+
ユーザー t98slidert98slider
提出日時 2023-05-26 23:16:29
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,474 bytes
コンパイル時間 1,772 ms
コンパイル使用メモリ 176,080 KB
実行使用メモリ 20,112 KB
最終ジャッジ日時 2023-08-26 13:43:28
合計ジャッジ時間 15,506 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 92 ms
7,444 KB
testcase_03 AC 91 ms
7,568 KB
testcase_04 AC 91 ms
7,592 KB
testcase_05 AC 93 ms
7,480 KB
testcase_06 AC 93 ms
7,452 KB
testcase_07 AC 97 ms
8,028 KB
testcase_08 AC 101 ms
8,292 KB
testcase_09 AC 98 ms
7,976 KB
testcase_10 AC 99 ms
8,268 KB
testcase_11 AC 100 ms
8,044 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 1 ms
4,380 KB
testcase_17 AC 1 ms
4,380 KB
testcase_18 AC 96 ms
9,064 KB
testcase_19 AC 101 ms
9,112 KB
testcase_20 AC 88 ms
7,956 KB
testcase_21 AC 85 ms
7,980 KB
testcase_22 AC 88 ms
7,976 KB
testcase_23 AC 98 ms
8,224 KB
testcase_24 AC 99 ms
8,120 KB
testcase_25 AC 96 ms
8,008 KB
testcase_26 AC 91 ms
7,996 KB
testcase_27 AC 133 ms
8,064 KB
testcase_28 AC 111 ms
7,972 KB
testcase_29 AC 97 ms
7,964 KB
testcase_30 AC 91 ms
8,152 KB
testcase_31 AC 88 ms
7,956 KB
testcase_32 AC 84 ms
8,048 KB
testcase_33 AC 86 ms
8,124 KB
testcase_34 AC 86 ms
8,124 KB
testcase_35 AC 82 ms
7,976 KB
testcase_36 AC 79 ms
7,736 KB
testcase_37 TLE -
testcase_38 AC 82 ms
8,100 KB
testcase_39 AC 86 ms
8,092 KB
testcase_40 AC 87 ms
8,096 KB
testcase_41 AC 88 ms
7,976 KB
testcase_42 AC 90 ms
8,056 KB
testcase_43 AC 89 ms
8,008 KB
testcase_44 AC 90 ms
8,132 KB
testcase_45 AC 90 ms
8,276 KB
testcase_46 TLE -
権限があれば一括ダウンロードができます

ソースコード

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<multiset<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++){
        for(auto &&j : g[i]){
            if(g[j].size() >= sqN){
                G[i].emplace_back(j);
                fri[j].insert(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].find(pos[v]) != fri[u].end());
        }
        cout << (flag ? "Yes" : "No") << '\n';
        if(!flag) continue;
        for(auto &&c : G[u]){
            fri[c].erase(fri[c].find(pos[u]));
            fri[c].insert(pos[v]);
        }
        pos[u] = pos[v];
    }
}
0