結果

問題 No.1983 [Cherry 4th Tune C] 南の島のマーメイド
ユーザー akakimidoriakakimidori
提出日時 2022-03-29 21:28:26
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 214 ms / 4,000 ms
コード長 1,525 bytes
コンパイル時間 1,467 ms
コンパイル使用メモリ 89,204 KB
実行使用メモリ 60,348 KB
最終ジャッジ日時 2024-04-17 12:31:40
合計ジャッジ時間 7,832 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 4 ms
5,376 KB
testcase_09 AC 5 ms
5,376 KB
testcase_10 AC 8 ms
5,376 KB
testcase_11 AC 8 ms
5,376 KB
testcase_12 AC 5 ms
5,376 KB
testcase_13 AC 100 ms
12,800 KB
testcase_14 AC 123 ms
18,176 KB
testcase_15 AC 118 ms
13,792 KB
testcase_16 AC 46 ms
10,608 KB
testcase_17 AC 127 ms
20,096 KB
testcase_18 AC 105 ms
13,696 KB
testcase_19 AC 152 ms
22,400 KB
testcase_20 AC 104 ms
13,056 KB
testcase_21 AC 123 ms
18,648 KB
testcase_22 AC 159 ms
25,600 KB
testcase_23 AC 202 ms
27,308 KB
testcase_24 AC 213 ms
27,264 KB
testcase_25 AC 203 ms
27,392 KB
testcase_26 AC 208 ms
27,392 KB
testcase_27 AC 203 ms
27,304 KB
testcase_28 AC 207 ms
27,264 KB
testcase_29 AC 211 ms
27,516 KB
testcase_30 AC 214 ms
27,264 KB
testcase_31 AC 207 ms
27,264 KB
testcase_32 AC 207 ms
27,136 KB
testcase_33 AC 2 ms
5,376 KB
testcase_34 AC 56 ms
10,240 KB
testcase_35 AC 152 ms
60,348 KB
testcase_36 AC 116 ms
16,512 KB
testcase_37 AC 2 ms
5,376 KB
testcase_38 AC 33 ms
5,376 KB
testcase_39 AC 152 ms
60,264 KB
testcase_40 AC 114 ms
17,332 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cassert>
#include <cstdint>
#include <iostream>
#include <string>
#include <vector>
#include <atcoder/dsu>

using namespace std;

using i32 = int32_t;

i32 read_int(void) {
    i32 v;
    cin >> v;
    return v;
}

void run(void) {
    const i32 n = read_int();
    const i32 m = read_int();
    const i32 q = read_int();
    vector<vector<i32>> g(n);
    for (i32 i = 0; i < m; ++i) {
        const i32 v = read_int() - 1;
        const i32 u = read_int() - 1;
        g[v].emplace_back(u);
        g[u].emplace_back(v);
    }
    vector<i32> ord(n, n);
    vector<i32> low(n, n);
    atcoder::dsu uf(n);
    i32 id = 0;
    auto dfs = [&](auto self, const i32 v, const i32 p) -> void {
        ord[v] = low[v] = id++;
        for (auto u: g[v]) {
            if (u == p) {
                continue;
            }
            if (ord[u] == n) {
                self(self, u, v);
                low[v] = min(low[v], low[u]);
                if (ord[v] < low[u]) {
                    uf.merge(v, u);
                }
            } else {
                low[v] = min(low[v], ord[u]);
            }
        }
    };
    for (i32 i = 0; i < n; ++i) {
    	if (ord[i] == n) {
    		dfs(dfs, i, n);
    	}
    }
    vector<string> answer{"No", "Yes"};
    for (i32 i = 0; i < q; ++i) {
        const i32 s = read_int() - 1;
        const i32 t = read_int() - 1;
        cout << answer[uf.same(s, t)] << '\n';
    }
}

int main(void) {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    run();
    return 0;
}
0