結果

問題 No.2319 Friends+
ユーザー umezo
提出日時 2024-04-11 00:36:36
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 376 ms / 3,000 ms
コード長 864 bytes
コンパイル時間 3,087 ms
コンパイル使用メモリ 248,600 KB
実行使用メモリ 101,248 KB
最終ジャッジ日時 2024-10-02 21:08:10
合計ジャッジ時間 18,303 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 45
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(v) v.begin(),v.end()
typedef long long ll;
template <class T> using V=vector<T>;
template <class T> using VV=V<V<T>>; //B(n,V<int>(n))
 
int main(){
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  
  int n,m;
  cin>>n>>m;
  V<int> P(n);
  V<bitset<20000>> wor(n),fri(n); 
  rep(i,n){
    cin>>P[i];
    P[i]--;
    wor[P[i]].set(i);
  }
  rep(i,m){
    int a,b;
    cin>>a>>b;
    a--,b--;
    fri[a].set(b);
    fri[b].set(a);
  }
  int q;
  cin>>q;
  rep(i,q){
    int x,y;
    cin>>x>>y;
    x--,y--;
    if(P[x]==P[y]){
      cout<<"No\n";
    }
    else{
      if((wor[P[y]]&fri[x]).any()){
        cout<<"Yes\n";
        wor[P[x]].reset(x);
        P[x]=P[y];
        wor[P[x]].set(x);
      }
      else cout<<"No\n";
    }
  }
  
  return 0;
}
0