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 <iostream>
#include <string>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string.h>
#include <numeric>
#include <iostream>
#include <queue>
#include <assert.h>
#include <map>
#include <set>
#include <limits.h>
#include <random>
#include <chrono>
using namespace std;
#define ll long long
#define ld long double
const int MX = 300005;
const int BLOCK = 105;
const ll inf = 8000000000000000069ll;
const ll mod = 1e9 + 7;
const ll inv2 = (mod + 1) / 2;
const int dxh[] = {1, 1, -1, -1, 2, 2, -2, -2};
const int dyh[] = {2, -2, 2, -2, 1, -1, 1, -1}; // horse
const int dx[] = {1, -1, 0, 0, 0, 0};
const int dy[] = {0, 0, 1, -1, 0, 0}; // adj
const int dz[] = {0, 0, 0, 0, 1, -1};
const int dxd[] = {1, 1, 1, 0, -1, -1, -1, 0};
const int dyd[] = {1, 0, -1, -1, -1, 0, 1, 1}; // diag
int n, m, k, col[MX];
vector<int> adj[MX];
ll dp[MX][40];
int main(){
cin.tie(0) -> sync_with_stdio(0);
cin >> n >> m >> k;
for(int i = 1; i <= n; i ++) cin >> col[i];
for(int u, v, i = 0; i < m; i ++){
cin >> u >> v;
adj[u].push_back(v);
adj[v].push_back(u);
}
ll ans = 0ll;
for(int msk = 1; msk < (1 << k); msk ++){
for(int i = 1; i <= n; i ++){
dp[i][msk] = 0;
if((msk & (1 << (col[i] - 1))) == 0) continue;
if(msk - (1 << (col[i] - 1)) == 0) dp[i][msk] = 1;
for(int nx : adj[i])
dp[i][msk] += dp[nx][msk - (1 << (col[i] - 1))];
ans += dp[i][msk];
}
}
ans -= n;
cout << ans << endl;
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... |