結果

問題 No.2319 Friends+
ユーザー 👑 emthrmemthrm
提出日時 2023-05-26 21:57:45
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 313 ms / 3,000 ms
コード長 1,473 bytes
コンパイル時間 2,946 ms
コンパイル使用メモリ 247,640 KB
実行使用メモリ 101,316 KB
最終ジャッジ日時 2023-08-26 11:28:44
合計ジャッジ時間 14,711 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 166 ms
101,128 KB
testcase_03 AC 165 ms
100,980 KB
testcase_04 AC 163 ms
100,820 KB
testcase_05 AC 169 ms
100,816 KB
testcase_06 AC 163 ms
100,980 KB
testcase_07 AC 301 ms
101,040 KB
testcase_08 AC 302 ms
101,016 KB
testcase_09 AC 305 ms
100,840 KB
testcase_10 AC 305 ms
100,892 KB
testcase_11 AC 313 ms
100,992 KB
testcase_12 AC 3 ms
4,556 KB
testcase_13 AC 3 ms
4,820 KB
testcase_14 AC 3 ms
4,632 KB
testcase_15 AC 3 ms
4,632 KB
testcase_16 AC 3 ms
4,628 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 197 ms
101,008 KB
testcase_19 AC 223 ms
100,768 KB
testcase_20 AC 180 ms
100,976 KB
testcase_21 AC 177 ms
100,836 KB
testcase_22 AC 174 ms
101,012 KB
testcase_23 AC 186 ms
101,092 KB
testcase_24 AC 185 ms
100,816 KB
testcase_25 AC 173 ms
100,880 KB
testcase_26 AC 178 ms
100,832 KB
testcase_27 AC 186 ms
101,068 KB
testcase_28 AC 183 ms
101,092 KB
testcase_29 AC 174 ms
101,228 KB
testcase_30 AC 174 ms
100,980 KB
testcase_31 AC 177 ms
101,008 KB
testcase_32 AC 173 ms
101,088 KB
testcase_33 AC 177 ms
100,780 KB
testcase_34 AC 177 ms
100,944 KB
testcase_35 AC 175 ms
101,020 KB
testcase_36 AC 216 ms
100,880 KB
testcase_37 AC 139 ms
100,960 KB
testcase_38 AC 164 ms
101,080 KB
testcase_39 AC 161 ms
100,816 KB
testcase_40 AC 165 ms
100,976 KB
testcase_41 AC 164 ms
101,316 KB
testcase_42 AC 169 ms
101,028 KB
testcase_43 AC 173 ms
100,960 KB
testcase_44 AC 164 ms
101,016 KB
testcase_45 AC 153 ms
101,028 KB
testcase_46 AC 144 ms
101,196 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
using ll = long long;
constexpr int INF = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr double EPS = 1e-8;
constexpr int MOD = 998244353;
// constexpr int MOD = 1000000007;
constexpr int DY4[]{1, 0, -1, 0}, DX4[]{0, -1, 0, 1};
constexpr int DY8[]{1, 1, 0, -1, -1, -1, 0, 1};
constexpr int DX8[]{0, -1, -1, -1, 0, 1, 1, 1};
template <typename T, typename U>
inline bool chmax(T& a, U b) { return a < b ? (a = b, true) : false; }
template <typename T, typename U>
inline bool chmin(T& a, U b) { return a > b ? (a = b, true) : false; }
struct IOSetup {
  IOSetup() {
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    std::cout << fixed << setprecision(20);
  }
} iosetup;

int main() {
  constexpr int N = 20000;
  int n, m; cin >> n >> m;
  vector<int> p(n);
  vector<bitset<N>> worlds(n);
  REP(i, n) {
    cin >> p[i]; --p[i];
    worlds[p[i]].set(i);
  }
  vector<bitset<N>> fri(n);
  while (m--) {
    int a, b; cin >> a >> b; --a; --b;
    fri[a].set(b);
    fri[b].set(a);
  }
  int q; cin >> q;
  while (q--) {
    int x, y; cin >> x >> y; --x; --y;
    if (p[x] != p[y] && (fri[x] & worlds[p[y]]).any()) {
      cout << "Yes\n";
      worlds[p[x]].reset(x);
      p[x] = p[y];
      worlds[p[x]].set(x);
    } else {
      cout << "No\n";
    }
  }
  return 0;
}
0