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>
#define pb push_back
#define F first
#define S second
#define debug(x) cout << #x << "= " << x << ", "
#define ll long long
#define fast ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define SZ(x) (int) x.size()
#define wall cout << endl;
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define int long long
const int maxn = 3e5 + 10 , maxk = 5;
int n , m , k , ar[maxn] , dp[maxn][(1 << maxk)];
vector <int> adj[maxn];
int32_t main()
{
fast;
cin >> n >> m >> k;
for(int i = 1 ; i <= n ; i++)
{
cin >> ar[i];
ar[i]--;
dp[i][(1 << ar[i])] = 1;
}
for(int i = 0 ; i < m ; i++)
{
int v , u; cin >> v >> u;
adj[v].pb(u);
adj[u].pb(v);
}
int ans = 0;
for(int mask = 3 ; mask < (1 << k) ; mask++)
{
if(__builtin_popcount(mask) == 1) continue;
for(int i = 1 ; i <= n ; i++) if((mask >> ar[i]) & 1)
{
int m2 = mask ^ (1 << ar[i]);
for(auto u : adj[i])
dp[i][mask] += dp[u][m2];
ans += dp[i][mask];
}
}
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... |