結果

問題 No.2319 Friends+
ユーザー Yaowei LyuYaowei Lyu
提出日時 2023-05-26 21:57:40
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,492 bytes
コンパイル時間 3,644 ms
コンパイル使用メモリ 254,732 KB
実行使用メモリ 23,600 KB
最終ジャッジ日時 2023-08-26 11:28:26
合計ジャッジ時間 16,797 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 141 ms
7,516 KB
testcase_03 AC 141 ms
7,452 KB
testcase_04 AC 130 ms
7,516 KB
testcase_05 AC 129 ms
7,480 KB
testcase_06 AC 140 ms
7,536 KB
testcase_07 AC 97 ms
8,008 KB
testcase_08 AC 97 ms
8,068 KB
testcase_09 AC 100 ms
8,108 KB
testcase_10 AC 97 ms
8,080 KB
testcase_11 AC 96 ms
8,216 KB
testcase_12 AC 2 ms
4,380 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,380 KB
testcase_17 AC 1 ms
4,380 KB
testcase_18 AC 88 ms
9,120 KB
testcase_19 AC 99 ms
9,100 KB
testcase_20 AC 84 ms
8,020 KB
testcase_21 AC 84 ms
8,128 KB
testcase_22 AC 92 ms
8,048 KB
testcase_23 AC 96 ms
8,332 KB
testcase_24 AC 92 ms
8,136 KB
testcase_25 AC 90 ms
8,012 KB
testcase_26 AC 96 ms
7,992 KB
testcase_27 AC 172 ms
8,012 KB
testcase_28 AC 133 ms
8,104 KB
testcase_29 AC 106 ms
8,060 KB
testcase_30 AC 89 ms
8,016 KB
testcase_31 AC 86 ms
8,108 KB
testcase_32 AC 82 ms
7,988 KB
testcase_33 AC 81 ms
8,040 KB
testcase_34 AC 78 ms
8,064 KB
testcase_35 AC 82 ms
8,124 KB
testcase_36 AC 77 ms
7,748 KB
testcase_37 AC 92 ms
7,540 KB
testcase_38 AC 83 ms
7,972 KB
testcase_39 AC 79 ms
8,036 KB
testcase_40 AC 83 ms
8,048 KB
testcase_41 AC 82 ms
7,976 KB
testcase_42 AC 87 ms
7,992 KB
testcase_43 AC 97 ms
8,120 KB
testcase_44 AC 99 ms
8,228 KB
testcase_45 AC 113 ms
8,308 KB
testcase_46 TLE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using i64 = int64_t;
constexpr i64 mod = 998244353;
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n, m;
    cin >> n >> m;
    vector<int> p(n + 1);
    for (int i = 1; i <= n; i += 1) {
        cin >> p[i];
    }
    vector<vector<int>> g(n + 1), sg(n + 1);
    vector<multiset<int>> adj(n + 1);
    int sn = 1000;
    for (int i = 0, x, y; i < m; i += 1) {
        cin >> x >> y;
        g[x].push_back(y);
        g[y].push_back(x);
    }
    for (int i = 1; i <= n; i += 1) {
        if (g[i].size() > sn) {
            for (int j : g[i]) {
                sg[j].push_back(i);
                adj[i].insert(p[j]);
            }
        }
    }
    int q;
    cin >> q;
    for (int i = 0, x, y; i < q; i += 1) {
        cin >> x >> y;
        if (p[x] == p[y]) {
            cout << "No\n";
        } else {
            bool ok = false;
            if (g[x].size() <= sn) {
                for (int z : g[x]) {
                    if (p[z] == p[y]) {
                        ok = true;
                    }
                }
            } else {
                ok = adj[x].contains(p[y]);
            }
            if (ok) {
                cout << "Yes\n";
                for (int z : sg[x]) {
                    adj[z].extract(p[x]);
                    adj[z].insert(p[y]);
                }
                p[x] = p[y];
            } else {
                cout << "No\n";
            }
        }
    }
}
0