Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma region includes and predefines
- #include <iostream>
- #include <vector>
- #include <algorithm>
- #include <functional>
- #include <string>
- #include <cstring>
- #include <map>
- #include <unordered_map>
- #include <set>
- #include <unordered_set>
- #include <queue>
- #include <stack>
- #include <cmath>
- #pragma GCC target("arch=sandybridge")
- #pragma GCC optimize("O3")
- #pragma GCC optimize("expensive-optimizations")
- #pragma GCC optimize("tree-parallelize-loops=4")
- using namespace std;
- #ifndef __typeof
- #define __typeof(T) decltype(T)
- #endif
- //#define endl "\n"
- #define fs first
- #define sc second
- #define pb emplace_back
- #define rep(i,a,b) for (__typeof(b) i = (a); i < (b); ++i)
- #define iter(it, c) for(__typeof((c).begin()) it = (c).begin(); it != (c).end(); ++it)
- typedef long long ll;
- typedef unsigned long long ul;
- typedef pair<ll,ll> pl;
- typedef pair<ul,ul> pu;
- typedef vector<ll> vl;
- typedef vector<ul> vu;
- typedef vector<vl> vl2;
- typedef vector<vu> vu2;
- #pragma GCC diagnostic ignored "-Wshift-count-overflow"
- const ll inf = ~(1<<31);
- const ul inf_u = ~(1<<32);
- #pragma GCC diagnostic pop
- const double dlo = 1e-9;
- const double pi = acos(-1);
- #pragma endregion
- ul k;
- ul arr[300010];
- vector<vector<ul>> mem(300010, vector<ul>(32,inf_u));
- struct graph
- {
- vector<vector<pu>> edg;
- graph(){}
- graph(ul n){edg.resize(n);}
- void connect1(ul v, ul u, ul w=1){edg[v].pb(pu{w,u});}
- void connect(ul v, ul u, ul w=1){connect1(v,u,w);connect1(u,v,w);}
- ul dp(ul at, int bits, int cnt)
- {
- if(mem[at][bits]!=inf_u)return mem[at][bits];
- if(cnt==k)return 1;
- ul sm = (cnt==1?0:1);
- rep(i,0,edg[at].size())
- {
- if(!((bits>>arr[edg[at][i].sc])&1))
- {
- sm += dp(edg[at][i].sc,bits|(1<<arr[edg[at][i].sc]),cnt+1);
- }
- }
- return mem[at][bits]=sm;
- }
- };
- int main()
- {
- ios::sync_with_stdio(false);
- cin.tie(NULL);
- ul n,m;
- cin >> n >> m >> k;
- graph g(n);
- rep(i,0,n)
- {
- cin >> arr[i];
- }
- rep(i,0,m)
- {
- ul v,u;
- cin >> v >> u;
- g.connect(v-1,u-1);
- }
- ul ans = 0;
- rep(i,0,n)
- {
- ans += g.dp(i,0|(1<<arr[i]),1);
- }
- cout << ans;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement