結果

問題 No.2948 move move rotti
ユーザー gazellegazelle
提出日時 2024-10-25 22:08:09
言語 C++23(gcc13)
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 361 ms / 4,000 ms
コード長 9,236 bytes
コンパイル時間 6,017 ms
コンパイル使用メモリ 416,884 KB
実行使用メモリ 29,416 KB
最終ジャッジ日時 2024-10-25 22:08:43
合計ジャッジ時間 11,891 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 10 ms
27,048 KB
testcase_01 AC 9 ms
26,880 KB
testcase_02 AC 9 ms
26,880 KB
testcase_03 AC 354 ms
29,160 KB
testcase_04 AC 112 ms
29,280 KB
testcase_05 AC 10 ms
26,896 KB
testcase_06 AC 10 ms
26,736 KB
testcase_07 AC 127 ms
29,188 KB
testcase_08 AC 354 ms
29,160 KB
testcase_09 AC 354 ms
29,292 KB
testcase_10 AC 9 ms
26,736 KB
testcase_11 AC 9 ms
26,804 KB
testcase_12 AC 35 ms
27,232 KB
testcase_13 AC 171 ms
29,228 KB
testcase_14 AC 122 ms
29,292 KB
testcase_15 AC 339 ms
29,160 KB
testcase_16 AC 355 ms
29,292 KB
testcase_17 AC 336 ms
29,288 KB
testcase_18 AC 298 ms
29,292 KB
testcase_19 AC 218 ms
29,284 KB
testcase_20 AC 249 ms
29,284 KB
testcase_21 AC 361 ms
29,416 KB
testcase_22 AC 189 ms
29,288 KB
testcase_23 AC 297 ms
29,396 KB
testcase_24 AC 175 ms
29,288 KB
testcase_25 AC 210 ms
29,164 KB
testcase_26 AC 10 ms
26,932 KB
testcase_27 AC 9 ms
26,932 KB
testcase_28 AC 21 ms
26,868 KB
testcase_29 AC 10 ms
26,800 KB
testcase_30 AC 13 ms
27,096 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <array>
#include <bit>
#include <bitset>
#include <cassert>
#include <chrono>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define FOR(i, n, m) for (int i = n; i < (int)m; ++i)
#define REP(i, n) FOR (i, 0, n)
#define ALL(v) v.begin(), v.end()
#define PB push_back
using namespace std;
using ll = long long;
constexpr long long INF = 1000000000;
constexpr long long MOD = 998244353;
using P = pair<int, int>;

template <typename T1, typename T2>
inline bool chmax(T1& a, T2 b) {
    return a < b && (a = b, true);
}

template <typename T1, typename T2>
inline bool chmin(T1& a, T2 b) {
    return a > b && (a = b, true);
}

template <typename T1, typename T2>
ostream& operator<<(ostream& os, pair<T1, T2> p) {
    os << to_string(p.first) << " " << to_string(p.second);
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, vector<T>& v) {
    REP (i, v.size()) {
        if (i) os << " ";
        os << to_string(v[i]);
    }
    return os;
}

struct modint {
    ll n;

   public:
    modint(const ll n = 0) : n((n % MOD + MOD) % MOD) {}
    static modint pow(modint a, int m) {
        modint r = 1;
        while (m > 0) {
            if (m & 1) {
                r *= a;
            }
            a = (a * a);
            m /= 2;
        }
        return r;
    }
    modint& operator++() {
        *this += 1;
        return *this;
    }
    modint& operator--() {
        *this -= 1;
        return *this;
    }
    modint operator++(int) {
        modint ret = *this;
        *this += 1;
        return ret;
    }
    modint operator--(int) {
        modint ret = *this;
        *this -= 1;
        return ret;
    }
    modint operator~() const { return (this->pow(n, MOD - 2)); }  // inverse
    friend bool operator==(const modint& lhs, const modint& rhs) {
        return lhs.n == rhs.n;
    }
    friend bool operator<(const modint& lhs, const modint& rhs) {
        return lhs.n < rhs.n;
    }
    friend bool operator>(const modint& lhs, const modint& rhs) {
        return lhs.n > rhs.n;
    }
    friend modint& operator+=(modint& lhs, const modint& rhs) {
        lhs.n += rhs.n;
        if (lhs.n >= MOD) lhs.n -= MOD;
        return lhs;
    }
    friend modint& operator-=(modint& lhs, const modint& rhs) {
        lhs.n -= rhs.n;
        if (lhs.n < 0) lhs.n += MOD;
        return lhs;
    }
    friend modint& operator*=(modint& lhs, const modint& rhs) {
        lhs.n = (lhs.n * rhs.n) % MOD;
        return lhs;
    }
    friend modint& operator/=(modint& lhs, const modint& rhs) {
        lhs.n = (lhs.n * (~rhs).n) % MOD;
        return lhs;
    }
    friend modint operator+(const modint& lhs, const modint& rhs) {
        return modint(lhs.n + rhs.n);
    }
    friend modint operator-(const modint& lhs, const modint& rhs) {
        return modint(lhs.n - rhs.n);
    }
    friend modint operator*(const modint& lhs, const modint& rhs) {
        return modint(lhs.n * rhs.n);
    }
    friend modint operator/(const modint& lhs, const modint& rhs) {
        return modint(lhs.n * (~rhs).n);
    }
};
istream& operator>>(istream& is, modint m) {
    is >> m.n;
    return is;
}
ostream& operator<<(ostream& os, modint m) {
    os << m.n;
    return os;
}

#define MAX_N 3030303
long long extgcd(long long a, long long b, long long& x, long long& y) {
    long long d = a;
    if (b != 0) {
        d = extgcd(b, a % b, y, x);
        y -= (a / b) * x;
    } else {
        x = 1;
        y = 0;
    }
    return d;
}
long long mod_inverse(long long a, long long m) {
    long long x, y;
    if (extgcd(a, m, x, y) == 1) return (m + x % m) % m;
    else return -1;
}
vector<long long> fact(MAX_N + 1, INF);
long long mod_fact(long long n, long long& e) {
    if (fact[0] == INF) {
        fact[0] = 1;
        if (MAX_N != 0) fact[1] = 1;
        for (ll i = 2; i <= MAX_N; ++i) {
            fact[i] = (fact[i - 1] * i) % MOD;
        }
    }
    e = 0;
    if (n == 0) return 1;
    long long res = mod_fact(n / MOD, e);
    e += n / MOD;
    if ((n / MOD) % 2 != 0) return (res * (MOD - fact[n % MOD])) % MOD;
    return (res * fact[n % MOD]) % MOD;
}
// return nCk
modint mod_comb(long long n, long long k) {
    if (n < 0 || k < 0 || n < k) return 0;
    long long e1, e2, e3;
    long long a1 = mod_fact(n, e1), a2 = mod_fact(k, e2),
              a3 = mod_fact(n - k, e3);
    if (e1 > e2 + e3) return 0;
    return (a1 * mod_inverse((a2 * a3) % MOD, MOD)) % MOD;
}

using mi = modint;

mi mod_pow(mi a, ll n) {
    mi ret = 1;
    mi tmp = a;
    while (n > 0) {
        if (n % 2) ret *= tmp;
        tmp = tmp * tmp;
        n /= 2;
    }
    return ret;
}

template <typename T>
T min_mul(T div, T lb) {
    return (lb % div) ? (((lb / div) + 1) * div) : lb;
}

template <typename T>
vector<T> enum_div(T n) {
    vector<T> left, right;
    for (T i = 1; i * i <= n; ++i) {
        if (n % i != 0) continue;
        left.push_back(i);
        if (n / i != i) right.push_back(n / i);
    }
    copy(right.rbegin(), right.rend(), back_inserter(left));
    return left;
}

template <typename T>
vector<pair<T, size_t>> sorted(const vector<T>& v, bool desc = false) {
    vector<pair<T, size_t>> ret(v.size());
    ranges::transform(v, ret.begin(), [i = 0](const T& e) mutable {
        return make_pair(e, i++);
    });
    if (desc) ranges::sort(ret, ranges::greater());
    else ranges::sort(ret, ranges::less());
    return ret;
}

struct UnionFind {
    vector<int> data;

    UnionFind() = default;

    explicit UnionFind(size_t sz) : data(sz, -1) {}

    bool unite(int x, int y) {
        x = find(x), y = find(y);
        if (x == y) return false;
        if (data[x] > data[y]) swap(x, y);
        data[x] += data[y];
        data[y] = x;
        return true;
    }

    int find(int k) {
        if (data[k] < 0) return (k);
        return data[k] = find(data[k]);
    }

    int size(int k) { return -data[find(k)]; }

    bool same(int x, int y) { return find(x) == find(y); }

    vector<vector<int>> groups() {
        int n = (int)data.size();
        vector<vector<int>> ret(n);
        for (int i = 0; i < n; ++i) {
            ret[find(i)].emplace_back(i);
        }
        ret.erase(remove_if(begin(ret), end(ret),
                            [&](const vector<int>& v) { return v.empty(); }),
                  end(ret));
        return ret;
    }
};

template <typename T>
struct BinaryIndexedTree {
   private:
    int n;
    vector<T> data;

   public:
    BinaryIndexedTree() = default;

    explicit BinaryIndexedTree(int n) : n(n) { data.assign(n + 1, T()); }

    explicit BinaryIndexedTree(const vector<T>& v)
        : BinaryIndexedTree((int)v.size()) {
        build(v);
    }

    void build(const vector<T>& v) {
        assert(n == (int)v.size());
        for (int i = 1; i <= n; i++) data[i] = v[i - 1];
        for (int i = 1; i <= n; i++) {
            int j = i + (i & -i);
            if (j <= n) data[j] += data[i];
        }
    }

    void apply(int k, const T& x) {
        for (++k; k <= n; k += k & -k) data[k] += x;
    }

    T prod(int r) const {
        T ret = T();
        for (; r > 0; r -= r & -r) ret += data[r];
        return ret;
    }

    T prod(int l, int r) const { return prod(r) - prod(l); }

    int lower_bound(T x) const {
        int i = 0;
        for (int k = 1 << (__lg(n) + 1); k > 0; k >>= 1) {
            if (i + k <= n && data[i + k] < x) {
                x -= data[i + k];
                i += k;
            }
        }
        return i;
    }

    int upper_bound(T x) const {
        int i = 0;
        for (int k = 1 << (__lg(n) + 1); k > 0; k >>= 1) {
            if (i + k <= n && data[i + k] <= x) {
                x -= data[i + k];
                i += k;
            }
        }
        return i;
    }
};

void solve() {
    int n, m, k;
    cin >> n >> m >> k;
    vector<int> x(k);
    REP (i, k) cin >> x[i];
    vector<vector<int>> g(n);
    REP (i, m) {
        int u, v;
        cin >> u >> v;
        g[u - 1].PB(v - 1);
        g[v - 1].PB(u - 1);
    }
    vector<vector<vector<bool>>> c(
        n, vector<vector<bool>>(n, vector<bool>(n + 1, false)));
    REP (i, n) {
        vector<vector<bool>> dp((1 << n), vector<bool>(n, false));
        dp[(1 << i)][i] = true;
        REP (bit, (1 << n)) {
            REP (j, n) {
                if (not((1 << j) & bit)) continue;
                for (auto& l : g[j]) {
                    if (not((1 << l) & bit)) continue;
                    dp[bit][j] = dp[bit][j] | dp[bit - (1 << j)][l];
                }
                c[i][j][popcount(static_cast<unsigned>(bit))] =
                    c[i][j][popcount(static_cast<unsigned>(bit))] | dp[bit][j];
            }
        }
    }
    bool ok = false;
    REP (i, n) {
        REP (j, n + 1) {
            bool g = true;
            REP (l, k) g &= c[x[l] - 1][i][j];
            if (g) ok = true;
        }
    }
    if (ok) cout << "Yes" << endl;
    else cout << "No" << endl;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int t;
    // cin >> t;
    t = 1;
    while (t--) solve();
}
0