This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define ll long long
#define oo 1e9
#define pii pair<int, int>
using namespace std;
const int MAX = 3e5 + 5;
int n, m, k;
int color[MAX];
vector<int> g[MAX];
ll dp[MAX][1 << 5];
void solve(){
cin >> n >> m >> k;
for (int i = 1; i <= n; i++)
{
cin >> color[i];
color[i]--;
dp[i][1 << color[i]] = 1;
}
for (int i = 0; i < m; i++)
{
int u, v; cin >> u >> v;
g[v].push_back(u);
g[u].push_back(v);
}
ll ans = 0;
for (int mask = 1; mask < (1 << k); mask++)
{
if(__popcount(mask) <= 1) continue;
for (int node = 1; node <= n; node++)
{
if(!(mask & (1 << color[node]))) continue;
for(int to:g[node]){
dp[node][mask] += dp[to][mask ^ (1 << color[node])];
}
ans += dp[node][mask];
}
}
cout << ans << '\n';
}
int main()
{
solve();
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |