結果

問題 No.2319 Friends+
ユーザー pointNpointN
提出日時 2023-05-26 23:59:30
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 343 ms / 3,000 ms
コード長 1,469 bytes
コンパイル時間 1,448 ms
コンパイル使用メモリ 132,312 KB
実行使用メモリ 101,188 KB
最終ジャッジ日時 2023-08-26 14:10:06
合計ジャッジ時間 14,564 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 185 ms
101,112 KB
testcase_03 AC 182 ms
100,932 KB
testcase_04 AC 175 ms
100,956 KB
testcase_05 AC 175 ms
100,912 KB
testcase_06 AC 183 ms
100,848 KB
testcase_07 AC 341 ms
100,904 KB
testcase_08 AC 336 ms
101,008 KB
testcase_09 AC 338 ms
100,792 KB
testcase_10 AC 343 ms
100,904 KB
testcase_11 AC 339 ms
100,872 KB
testcase_12 AC 3 ms
4,560 KB
testcase_13 AC 2 ms
4,564 KB
testcase_14 AC 3 ms
4,576 KB
testcase_15 AC 2 ms
4,580 KB
testcase_16 AC 3 ms
4,620 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 213 ms
101,040 KB
testcase_19 AC 242 ms
100,984 KB
testcase_20 AC 200 ms
101,044 KB
testcase_21 AC 195 ms
100,984 KB
testcase_22 AC 201 ms
100,828 KB
testcase_23 AC 231 ms
100,992 KB
testcase_24 AC 211 ms
101,024 KB
testcase_25 AC 211 ms
101,016 KB
testcase_26 AC 207 ms
101,188 KB
testcase_27 AC 209 ms
100,880 KB
testcase_28 AC 199 ms
101,072 KB
testcase_29 AC 197 ms
100,980 KB
testcase_30 AC 199 ms
101,008 KB
testcase_31 AC 199 ms
100,988 KB
testcase_32 AC 195 ms
101,000 KB
testcase_33 AC 195 ms
101,100 KB
testcase_34 AC 192 ms
101,064 KB
testcase_35 AC 188 ms
101,052 KB
testcase_36 AC 234 ms
100,944 KB
testcase_37 AC 154 ms
101,088 KB
testcase_38 AC 180 ms
101,020 KB
testcase_39 AC 178 ms
100,860 KB
testcase_40 AC 180 ms
100,788 KB
testcase_41 AC 187 ms
100,928 KB
testcase_42 AC 183 ms
100,928 KB
testcase_43 AC 183 ms
101,036 KB
testcase_44 AC 183 ms
100,828 KB
testcase_45 AC 177 ms
100,896 KB
testcase_46 AC 175 ms
100,880 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#include <map>
#include <unordered_map>
#include <set>
#include <fstream>
#include <chrono>
#include <random>
#include <bitset>
//#include <atcoder/all>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(x) ((int)(x).size())
#define pb push_back
using ll = long long;
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}


int main(){  
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int N,M; cin >> N >> M;
  vector<bitset<20000>> P(N);
  vector<bitset<20000>> B(N);
  vector<int> W(N);
  rep(i,N){
    int a; cin >> a; a--;
    W[i] = a;
    P[a].set(i);
  }
  rep(i,M){
    int a,b; cin >> a >> b; a--; b--;
    if(a==b) continue;
    B[a].set(b);
    B[b].set(a);
  }
  int Q; cin >> Q;
  while(Q--){
    int x,y; cin >> x >> y; x--; y--;
    if(W[x]==W[y]) cout << "No\n";
    else{
      if((P[W[y]]&B[x]).any()){
        cout << "Yes\n";
        P[W[x]].reset(x);
        P[W[y]].set(x);
        W[x] = W[y];
      }
      else cout << "No\n";
    }
  }
  return 0;
}
0