Submission #1347791

#TimeUsernameProblemLanguageResultExecution timeMemory
1347791BlockOGPaths (BOI18_paths)C++20
100 / 100
152 ms91580 KiB
#include <bits/stdc++.h>

// mrrrowwww meeowwwww :3
// go play vivid/stasis! !! !!! https://vividstasis.gay

#define fo(i, a, b) for (auto i = (a); i < (b); i++)
#define of(i, a, b) for (auto i = (b); i-- > (a);)
#define f first
#define s second
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define be(a) a.begin(), a.end()
using namespace std;

int ____init = []{
    ios::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    return 0;
}();

int color[300000];
long long dp[300000][1 << 5];
vector<int> adj[300000];

int main() {
    int n, m, k; cin >> n >> m >> k;
    fo(i, 0, n) {
        cin >> color[i], color[i]--;
        fo(j, 0, 1 << k) if (!(j & (1 << color[i]))) dp[i][j] = 1;
    }

    fo(_, 0, m) {
        int a, b; cin >> a >> b; a--, b--;
        if (color[a] != color[b]) {
            adj[a].pb(b);
            adj[b].pb(a);
        }
    }

    vector<int> order(1 << k); iota(be(order), 0);
    sort(be(order), [](int a, int b) { return __builtin_popcount(a) > __builtin_popcount(b); });

    for (int l : order) {
        fo(i, 0, n) {
            if (l & (1 << color[i])) continue;
            for (int j : adj[i]) dp[i][l] += dp[j][l | (1 << color[i])];
        }
    }

    long long res = -n;
    fo(i, 0, n) res += dp[i][0];
    cout << res;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...