This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// Solved on 2022/10/18
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
const int MOD = 1e9+7;
#define F first
#define S second
#define PB push_back
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
void FASTIO() {ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); }
const int MXN = 3e5+5;
int n, m, k;
int A[MXN];
vi adj[MXN];
ll ways[1<<6][MXN];
void transit(int bits) {
for(int i = 0; i < n; i++) {
for(int j : adj[i]) {
for(int b = 0; b < (1<<k); b++) {
if(__builtin_popcount(b) != bits) continue;
if(b & (1 << A[j])) continue;
ways[b | (1 << A[j])][j] += ways[b][i];
}
}
}
}
int main() {
FASTIO();
cin >> n >> m >> k;
for(int i = 0; i < n; i++) {
cin >> A[i]; A[i]--;
ways[1<<A[i]][i]++;
}
for(int i = 0; i < m; i++) {
int a, b; cin >> a >> b; a--, b--;
adj[a].PB(b);
adj[b].PB(a);
}
for(int b = 1; b < k; b++) transit(b);
ll ans = 0;
for(int b = 0; b < (1<<k); b++) {
for(int i = 0; i < n; i++) {
ans += ways[b][i];
}
}
cout << ans-n << "\n";
return 0;
}
/*
*/
# | 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... |