結果

問題 No.2319 Friends+
ユーザー risujirohrisujiroh
提出日時 2023-05-26 21:53:53
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 330 ms / 3,000 ms
コード長 2,288 bytes
コンパイル時間 2,791 ms
コンパイル使用メモリ 250,848 KB
実行使用メモリ 101,228 KB
最終ジャッジ日時 2023-08-26 11:20:12
合計ジャッジ時間 16,525 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 177 ms
100,908 KB
testcase_03 AC 170 ms
100,980 KB
testcase_04 AC 166 ms
101,032 KB
testcase_05 AC 166 ms
100,900 KB
testcase_06 AC 169 ms
101,180 KB
testcase_07 AC 323 ms
101,100 KB
testcase_08 AC 324 ms
101,096 KB
testcase_09 AC 326 ms
100,932 KB
testcase_10 AC 327 ms
101,124 KB
testcase_11 AC 330 ms
101,096 KB
testcase_12 AC 3 ms
4,544 KB
testcase_13 AC 3 ms
4,624 KB
testcase_14 AC 3 ms
4,792 KB
testcase_15 AC 3 ms
4,816 KB
testcase_16 AC 3 ms
4,556 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 194 ms
100,824 KB
testcase_19 AC 238 ms
101,092 KB
testcase_20 AC 179 ms
101,228 KB
testcase_21 AC 180 ms
101,100 KB
testcase_22 AC 183 ms
101,028 KB
testcase_23 AC 207 ms
101,020 KB
testcase_24 AC 207 ms
101,184 KB
testcase_25 AC 189 ms
101,028 KB
testcase_26 AC 187 ms
101,032 KB
testcase_27 AC 185 ms
101,092 KB
testcase_28 AC 183 ms
100,968 KB
testcase_29 AC 184 ms
100,912 KB
testcase_30 AC 181 ms
100,960 KB
testcase_31 AC 181 ms
101,072 KB
testcase_32 AC 183 ms
100,936 KB
testcase_33 AC 178 ms
100,960 KB
testcase_34 AC 178 ms
101,016 KB
testcase_35 AC 176 ms
100,976 KB
testcase_36 AC 232 ms
101,008 KB
testcase_37 AC 140 ms
101,016 KB
testcase_38 AC 165 ms
100,956 KB
testcase_39 AC 164 ms
101,036 KB
testcase_40 AC 167 ms
101,032 KB
testcase_41 AC 167 ms
101,096 KB
testcase_42 AC 167 ms
100,972 KB
testcase_43 AC 166 ms
101,088 KB
testcase_44 AC 166 ms
101,036 KB
testcase_45 AC 155 ms
101,092 KB
testcase_46 AC 144 ms
101,012 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#if __INCLUDE_LEVEL__ == 0

#include <bits/stdc++.h>

using namespace std;

#include __BASE_FILE__

namespace std::ranges::views {

namespace {

void solve() {
  int n, m;
  cin >> tie(n, m);
  vector<int> p(n);
  vector<bitset<20000>> h(n);
  for (int i : iota(0, n)) {
    cin >> p[i];
    --p[i];
    h[p[i]][i] = 1;
  }
  vector<bitset<20000>> g(n);
  while (m--) {
    int a, b;
    cin >> tie(a, b);
    --a, --b;
    g[a][b] = 1;
    g[b][a] = 1;
  }
  int q;
  cin >> q;
  while (q--) {
    int x, y;
    cin >> tie(x, y);
    --x, --y;
    bool ans = [&]() -> bool {
      if (p[x] == p[y]) {
        return false;
      }
      if ((g[x] & h[p[y]]).none()) {
        return false;
      }
      h[p[x]][x] = 0;
      p[x] = p[y];
      h[p[x]][x] = 1;
      return true;
    }();
    cout << (ans ? "Yes\n" : "No\n");
  }
}

}  // namespace

}  // namespace std::ranges::views

using views::solve;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  solve();
}

#else  // __INCLUDE_LEVEL__

namespace std {

template <class T1, class T2>
istream& operator>>(istream& is, pair<T1, T2>& p) {
  return is >> p.first >> p.second;
}

template <class... Ts>
istream& operator>>(istream& is, tuple<Ts...>& t) {
  return apply([&is](auto&... xs) -> istream& { return (is >> ... >> xs); }, t);
}

template <class... Ts>
istream& operator>>(istream& is, tuple<Ts&...>&& t) {
  return is >> t;
}

template <class R, enable_if_t<!is_convertible_v<R, string>>* = nullptr>
auto operator>>(istream& is, R&& r) -> decltype(is >> *begin(r)) {
  for (auto&& e : r) {
    is >> e;
  }
  return is;
}

template <class T1, class T2>
ostream& operator<<(ostream& os, const pair<T1, T2>& p) {
  return os << p.first << ' ' << p.second;
}

template <class... Ts>
ostream& operator<<(ostream& os, const tuple<Ts...>& t) {
  auto f = [&os](const auto&... xs) -> ostream& {
    [[maybe_unused]] auto sep = "";
    ((os << exchange(sep, " ") << xs), ...);
    return os;
  };
  return apply(f, t);
}

template <class R, enable_if_t<!is_convertible_v<R, string_view>>* = nullptr>
auto operator<<(ostream& os, R&& r) -> decltype(os << *begin(r)) {
  auto sep = "";
  for (auto&& e : r) {
    os << exchange(sep, " ") << e;
  }
  return os;
}

}  // namespace std

#endif  // __INCLUDE_LEVEL__
0