結果

問題 No.1983 [Cherry 4th Tune C] 南の島のマーメイド
ユーザー KudeKude
提出日時 2022-06-17 22:29:52
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 237 ms / 4,000 ms
コード長 2,004 bytes
コンパイル時間 3,428 ms
コンパイル使用メモリ 223,212 KB
実行使用メモリ 38,388 KB
最終ジャッジ日時 2024-04-17 14:42:02
合計ジャッジ時間 10,027 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 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
11,264 KB
testcase_14 AC 129 ms
14,224 KB
testcase_15 AC 129 ms
13,696 KB
testcase_16 AC 54 ms
10,496 KB
testcase_17 AC 138 ms
15,360 KB
testcase_18 AC 115 ms
13,724 KB
testcase_19 AC 174 ms
18,816 KB
testcase_20 AC 118 ms
13,056 KB
testcase_21 AC 147 ms
15,360 KB
testcase_22 AC 185 ms
19,072 KB
testcase_23 AC 237 ms
21,408 KB
testcase_24 AC 231 ms
21,376 KB
testcase_25 AC 233 ms
21,504 KB
testcase_26 AC 229 ms
21,592 KB
testcase_27 AC 227 ms
21,504 KB
testcase_28 AC 223 ms
21,376 KB
testcase_29 AC 228 ms
21,632 KB
testcase_30 AC 219 ms
21,632 KB
testcase_31 AC 222 ms
21,616 KB
testcase_32 AC 218 ms
21,504 KB
testcase_33 AC 2 ms
5,376 KB
testcase_34 AC 56 ms
10,112 KB
testcase_35 AC 139 ms
38,232 KB
testcase_36 AC 116 ms
16,496 KB
testcase_37 AC 2 ms
5,376 KB
testcase_38 AC 31 ms
5,376 KB
testcase_39 AC 134 ms
38,388 KB
testcase_40 AC 112 ms
17,204 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
namespace {
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-function"
#include<atcoder/all>
#pragma GCC diagnostic pop
using namespace std;
using namespace atcoder;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(i,n) for(int i = (int)(n) - 1; i >= 0; i--)
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
template<class T> bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; }
template<class T> bool chmin(T& a, const T& b) { if (b < a) { a = b; return true; } else return false; }
using ll = long long;
using P = pair<int,int>;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<ll>;
using VVL = vector<VL>;


dsu d;

std::pair<std::vector<int>, std::vector<int>> lowlink(std::vector<std::vector<int>>& to) {
    // returns a pair of (ord, low)
    std::pair<std::vector<int>, std::vector<int>> res;
    const int n = to.size();
    auto& ord = res.first;
    auto& low = res.second;
    ord.resize(n, -1);
    low.resize(n);
    int nxt_ord = 0;
    auto dfs = [&](auto&& self, int u, int parent=-1) -> void {
        low[u] = ord[u] = nxt_ord++;
        for(int v: to[u]) {
            if (v == parent) continue;
            if (ord[v] == -1) {
                self(self, v, u);
                if (low[v] < low[u]) low[u] = low[v];
            } else {
                if (ord[v] < low[u]) low[u] = ord[v];
            }
        }
        if (parent != -1 && ord[u] == low[u]) {
          d.merge(u, parent);
        }
    };
    for(int i = 0; i < n; i++) if (ord[i] == -1) dfs(dfs, i);
    return res;
}

} int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m, q;
  cin >> n >> m >> q;
  VVI to(n);
  rep(_, m) {
    int u, v;
    cin >> u >> v;
    u--, v--;
    to[u].emplace_back(v);
    to[v].emplace_back(u);
  }
  d = dsu(n);
  lowlink(to);
  rep(_, q) {
    int x, y;
    cin >> x >> y;
    cout << (d.same(x - 1, y - 1) ? "Yes\n" : "No\n");
  }
}
0