結果

問題 No.2319 Friends+
ユーザー t98slidert98slider
提出日時 2023-05-26 23:08:44
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,447 bytes
コンパイル時間 1,977 ms
コンパイル使用メモリ 175,864 KB
実行使用メモリ 30,944 KB
最終ジャッジ日時 2023-08-26 13:34:39
合計ジャッジ時間 16,208 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 192 ms
26,504 KB
testcase_08 AC 190 ms
26,532 KB
testcase_09 AC 185 ms
26,468 KB
testcase_10 AC 186 ms
26,528 KB
testcase_11 AC 185 ms
26,732 KB
testcase_12 AC 2 ms
4,384 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 WA -
testcase_19 AC 157 ms
26,052 KB
testcase_20 AC 1,102 ms
26,468 KB
testcase_21 AC 541 ms
26,464 KB
testcase_22 AC 2,030 ms
26,452 KB
testcase_23 AC 156 ms
26,272 KB
testcase_24 AC 151 ms
26,256 KB
testcase_25 AC 148 ms
26,264 KB
testcase_26 AC 150 ms
26,316 KB
testcase_27 AC 144 ms
26,592 KB
testcase_28 TLE -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
testcase_44 -- -
testcase_45 -- -
testcase_46 -- -
権限があれば一括ダウンロードができます

ソースコード

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