#include <bits/stdc++.h>
#define TASK "kasjdkasd"
#define endl '\n'
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define BIT(i,x) (((i)>>(x))&1)
#define FOR(i,a,b) for(int i = (a); i<=(b); i++)
#define FORD(i,a,b) for(int i = (a); i>=(b); i--)
#define all(C) C.begin(), C.end()
using namespace std;
using ll = long long;
using pii = pair<int,int>;
const int INT_LIM = 2147483647;
const ll LL_LIM = 9223372036854775807;
template <typename X> bool minimize(X &x, const X &y) {if (x>y){x = y; return true;}return false;}
template <typename X> bool maximize(X &x, const X &y) {if (x<y){x = y; return true;}return false;}
///------------------------------------------///
const int MOD = 1e9+7;
void add(int &x, const int &y)
{
x+=y;
if (x>=MOD) x-=MOD;
}
int n,m,k;
int a[300005];
vector<int> adj[300005];
void inp()
{
cin >> n >> m >> k;
FOR(i, 1, n) cin >> a[i];
FOR(i, 1, m)
{
int u,v;
cin >> u >> v;
adj[u].pb(v);
adj[v].pb(u);
}
}
int dp[300005][32];
void solve()
{
vector<int> msk;
FOR(i, 0, (1<<k)-1) msk.pb(i);
sort(all(msk), [&](int x, int y)
{
return __builtin_popcount(x) < __builtin_popcount(y);
});
int ans = 0;
for (auto mask:msk) FOR(i, 1, n) if (BIT(mask, a[i]-1))
{
if (__builtin_popcount(mask)==1)
{
dp[i][mask] = 1;
}
else
{
for (auto v:adj[i])
{
add(dp[i][mask], dp[v][mask^(1<<(a[i]-1))]);
}
add(ans, dp[i][mask]);
}
// cout << i << ' ' << mask << ' ' << dp[i][mask] << endl;
}
cout << ans;
}
signed main()
{
///--------------------------///
ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
if (fopen(TASK".INP","r")!=NULL)
{
freopen(TASK".INP","r",stdin);
freopen(TASK".OUT","w",stdout);
}
///--------------------------///
int NTEST = 1;
bool codeforces = 0;
if (codeforces) cin >> NTEST;
while (NTEST--)
{
inp();
solve();
}
return 0;
}
///------------------------------------------///
Compilation message (stderr)
paths.cpp: In function 'int main()':
paths.cpp:81:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
81 | freopen(TASK".INP","r",stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
paths.cpp:82:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
82 | freopen(TASK".OUT","w",stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# | 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... |