結果

問題 No.2319 Friends+
ユーザー milanis48663220milanis48663220
提出日時 2023-05-26 22:07:09
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 909 ms / 3,000 ms
コード長 2,612 bytes
コンパイル時間 1,583 ms
コンパイル使用メモリ 121,452 KB
実行使用メモリ 101,116 KB
最終ジャッジ日時 2023-08-26 11:44:57
合計ジャッジ時間 33,743 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 653 ms
100,968 KB
testcase_03 AC 643 ms
100,868 KB
testcase_04 AC 630 ms
100,824 KB
testcase_05 AC 606 ms
101,116 KB
testcase_06 AC 643 ms
100,776 KB
testcase_07 AC 909 ms
100,788 KB
testcase_08 AC 880 ms
100,820 KB
testcase_09 AC 894 ms
100,784 KB
testcase_10 AC 898 ms
100,904 KB
testcase_11 AC 893 ms
100,872 KB
testcase_12 AC 4 ms
4,548 KB
testcase_13 AC 4 ms
4,548 KB
testcase_14 AC 4 ms
4,596 KB
testcase_15 AC 4 ms
4,632 KB
testcase_16 AC 4 ms
4,648 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 670 ms
100,896 KB
testcase_19 AC 727 ms
100,912 KB
testcase_20 AC 662 ms
100,948 KB
testcase_21 AC 669 ms
101,096 KB
testcase_22 AC 671 ms
101,028 KB
testcase_23 AC 710 ms
100,776 KB
testcase_24 AC 717 ms
100,788 KB
testcase_25 AC 710 ms
100,780 KB
testcase_26 AC 705 ms
100,776 KB
testcase_27 AC 686 ms
100,936 KB
testcase_28 AC 676 ms
100,832 KB
testcase_29 AC 677 ms
100,828 KB
testcase_30 AC 665 ms
100,804 KB
testcase_31 AC 672 ms
100,996 KB
testcase_32 AC 678 ms
100,868 KB
testcase_33 AC 674 ms
100,888 KB
testcase_34 AC 678 ms
100,780 KB
testcase_35 AC 676 ms
100,832 KB
testcase_36 AC 727 ms
100,844 KB
testcase_37 AC 655 ms
100,828 KB
testcase_38 AC 671 ms
100,944 KB
testcase_39 AC 667 ms
100,840 KB
testcase_40 AC 672 ms
100,848 KB
testcase_41 AC 680 ms
100,824 KB
testcase_42 AC 674 ms
100,864 KB
testcase_43 AC 669 ms
100,844 KB
testcase_44 AC 677 ms
100,876 KB
testcase_45 AC 666 ms
100,776 KB
testcase_46 AC 674 ms
100,892 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <cmath>
#include <numeric>
#include <functional>
#include <cassert>
#include <bitset>

#define debug_value(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << #x << "=" << x << endl;
#define debug(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << x << endl;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

using namespace std;
typedef long long ll;

template<typename T>
vector<vector<T>> vec2d(int n, int m, T v){
    return vector<vector<T>>(n, vector<T>(m, v));
}

template<typename T>
vector<vector<vector<T>>> vec3d(int n, int m, int k, T v){
    return vector<vector<vector<T>>>(n, vector<vector<T>>(m, vector<T>(k, v)));
}

template<typename T>
void print_vector(vector<T> v, char delimiter=' '){
    if(v.empty()) {
        cout << endl;
        return;
    }
    for(int i = 0; i+1 < v.size(); i++) cout << v[i] << delimiter;
    cout << v.back() << endl;
}


struct UnionFind {
    vector<int> data;
    UnionFind(int size) : data(size, -1) {}
    bool unionSet(int x, int y) {
        x = root(x); y = root(y);
        if (x != y) {
        if (data[y] < data[x]) swap(x, y);
        data[x] += data[y]; data[y] = x;
        }
        return x != y;
    }
    bool findSet(int x, int y) {
        return root(x) == root(y);
    }
    int root(int x) {
        return data[x] < 0 ? x : data[x] = root(data[x]);
    }
    int size(int x) {
        return -data[root(x)];
    }
};

using bs = bitset<20000>;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    int n, m; cin >> n >> m;
    vector<int> p(n);
    for(int i = 0; i < n; i++) {
        cin >> p[i]; p[i]--;
    }
    vector<bs> f(n);
    for(int i = 0; i < m; i++){
        int a, b; cin >> a >> b; a--; b--;
        f[a][b] = 1;
        f[b][a] = 1;
    }
    int q; cin >> q;
    vector<bs> people(n);
    for(int i = 0; i < n; i++){
        people[p[i]][i] = 1;
    }
    while(q--){
        int x, y; cin >> x >> y; x--; y--;
        if(p[x] == p[y]){
            cout << "No" << endl;
            continue;
        }
        if((people[p[y]] & f[x]).count() > 0){
            cout << "Yes" << endl;
            people[p[x]][x] = 0;
            p[x] = p[y];
            people[p[x]][x] = 1;
        }else{
            cout << "No" << endl;
        }
    }
}
0