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>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
typedef long long ll;
using namespace std;
//using namespace __gnu_pbds;
#define FOR(i, x, y) for(ll i=x; i<y; i++)
#define FORNEG(i, x, y) for(ll i=x; i>y; i--)
//#define ordered_set tree<ll, null_type,less_equal<ll>, rb_tree_tag,tree_order_statistics_node_update>
#define fast() ios_base::sync_with_stdio(false);cin.tie(NULL)
ll dp[32][300001];
vector<ll> edges[300001];
vector<ll> colours;
int main(){
ll n,m,k;
cin >> n >> m >> k;
FOR(i,0,n){
ll temp; cin >> temp;
colours.push_back(temp-1);
}
FOR(i,0,m){
ll a,b;
cin >> a >> b;
a--;b--;
edges[a].push_back(b);
edges[b].push_back(a);
}
FOR(i,0,32) FOR(j,0,300001) dp[i][j] = 0;
FOR(i,0,n){
dp[1<<colours[i]][i] = 1;
}
FOR(p,1, 1<<k){
FOR(i,0,n){
for (auto&j : edges[i]){
FOR(q, 1, 1<<k){
if ((q|(1<<colours[i])) == p && ((q&(1<<colours[i])) == 0)){
dp[p][i] += dp[q][j];
}
}
}
}
}
ll ans = 0;
FOR(i,0,1<<k){
if (i==1 || i==2 || i==4 || i==8 || i==16) continue;
FOR(j,0,n){
ans += dp[i][j];
}
}
cout << ans << endl;
}
# | 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... |