結果

問題 No.1983 [Cherry 4th Tune C] 南の島のマーメイド
コンテスト
ユーザー kentakunkentakun
提出日時 2025-12-01 00:16:33
言語 C++17
(gcc 13.3.0 + boost 1.89.0)
結果
AC  
実行時間 713 ms / 4,000 ms
コード長 2,773 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,999 ms
コンパイル使用メモリ 206,888 KB
実行使用メモリ 60,092 KB
最終ジャッジ日時 2025-12-01 00:16:53
合計ジャッジ時間 19,606 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 41
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/stdc++.h>
#include <atcoder/dsu>
using namespace std;
using namespace atcoder;
#define ll long long
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define FOR(i, a, b) for (ll i = (a); i < (ll)(b); i++)
#define FORR(i, a, b) for (ll i = (a); i <= (ll)(b); i++)
#define repR(i, n) for (ll i = n - 1; i >= 0LL; i--)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define F first
#define S second
#define pb push_back
#define pu push
#define COUT(x) cout << (x) << "\n"
#define PQ(x) priority_queue<x>
#define PQR(x) priority_queue<x, vector<x>, greater<x>>
#define YES(n) cout << ((n) ? "YES\n" : "NO\n")
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n")
#define mp make_pair
#define sz(x) (ll)(x).size()
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef tuple<ll, ll, ll> tll;
const ll MOD = 998244353LL;
const ll INF = 1LL << 60;
using vll = vector<ll>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvll = vector<vll>;
using vstr = vector<string>;
using vc = vector<char>;
using vvc = vector<vc>;
template <class T>
constexpr void printArray(const vector<T> &vec, char split = ' ')
{
  rep(i, vec.size())
  {
    cout << vec[i];
    cout << (i == (int)vec.size() - 1 ? '\n' : split);
  }
}
template <class T>
inline bool chmax(T &a, T b)
{
  if (a < b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool chmin(T &a, T b)
{
  if (a > b)
  {
    a = b;
    return true;
  }
  return false;
}
ll dx[4] = {0, 1, 0, -1};
ll dy[4] = {1, 0, -1, 0};

int main()
{
  int timer = 0;
  ll N;
  cin >> N;
  ll m, q;
  cin >> m >> q;
  dsu uf(N);
  vvll G(N, vll(0));
  rep(i, m)
  {
    ll u, v;
    cin >> u >> v;
    u--;
    v--;
    G[u].pb(v);
    G[v].pb(u);
  }
  vector<int> ord(N, -1), low(N, -1);

  auto dfs = [&](auto dfs, int u, int p) -> void
  {
    ord[u] = low[u] = timer++;
    for (int v : G[u])
    {
      if (v == p)
        continue;
      if (ord[v] == -1)
      { // まだ見てない → 木辺
        dfs(dfs, v, u);
        low[u] = min(low[u], low[v]);
        if (low[v] > ord[u])
        {
          // (u, v) は橋
          uf.merge(u, v);
        }
      }
      else
      { // すでに見た → 後退辺
        low[u] = min(low[u], ord[v]);
      }
    }
  };
  rep(i, N)
  {
    if (ord[i] == -1)
    {
      dfs(dfs, i, -1);
    }
  }
  rep(i, q)
  {
    ll x, y;
    cin >> x >> y;
    x--;
    y--;
    if (uf.same(x, y))
    {
      cout << "Yes" << endl;
    }
    else
    {
      cout << "No" << endl;
    }
  }
}
/*cin.tie(0);
ios::sync_with_studio(false);
next_permutation(v.begin(), v.end())

cout << fixed << setprecision(10);
__int128

//ソート済み
v.erase(unique(v.begin(), v.end()), v.end());
__builtin_popcount(i)*/
0