제출 #1347324

#제출 시각아이디문제언어결과실행 시간메모리
1347324iamhereforfunPaths (BOI18_paths)C++20
53 / 100
63 ms31760 KiB
// Starcraft 2 enjoyer //

#include <bits/stdc++.h>

// #pragma GCC target("avx2")
// #pragma GCC optimize("O3")
// #pragma GCC optimize("unroll-loops")

using namespace std;

#define LSOne(X) ((X) & -(X))

const int N = 1e5 + 5;
const int M = 1 << 10;
const int K = 19;
const int LG = 11;
const int INF = 1e9 + 5;
const int C = 26;
const int B = 1000;
const int MOD = 998244353;

int n, m, k, a[N];
long long dp[N][1 << 5], ans;
vector<int> adj[N];

inline void solve()
{
    cin >> n >> m >> k;
    for (int x = 1; x <= n; x++)
    {
        cin >> a[x];
        a[x]--;
        dp[x][1 << a[x]] = 1;
    }
    for (int x = 0; x < m; x++)
    {
        int a, b;
        cin >> a >> b;
        adj[a].push_back(b);
        adj[b].push_back(a);
    }
    ans = 0;
    for (int x = 1; x < k; x++)
    {
        for (int y = 0; y <= (1 << k); y++)
        {
            if (__builtin_popcount(y) != x)
                continue;
            for (int z = 1; z <= n; z++)
            {
                if (dp[z][y] == 0)
                    continue;
                for (int i : adj[z])
                {
                    if (!(y >> a[i] & 1))
                    {
                        dp[i][y ^ (1 << a[i])] += dp[z][y];
                    }
                }
            }
        }
    }
    for (int x = 1; x <= n; x++)
    {
        for (int y = 0; y < (1 << k); y++)
        {
            if (__builtin_popcount(y) <= 1)
                continue;
            ans += dp[x][y];
            // cout << dp[x][y] << " " << x << " " << bitset<3>(y) << "\n";
        }
    }
    cout << ans << "\n";
}

signed main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t = 1;
    // cin >> t;
    for (int x = 1; x <= t; x++)
    {
        solve();
    }
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...