제출 #226972

#제출 시각아이디문제언어결과실행 시간메모리
226972anubhavdharPaths (BOI18_paths)C++14
100 / 100
798 ms60408 KiB
#include<bits/stdc++.h>

#define ll long long int
#define pb push_back
#define mp make_pair
#define FOR(i,n) for(i=0;i<(n);++i)
#define FORe(i,n) for(i=1;i<=(n);++i)
#define FORr(i,a,b) for(i=(a);i<(b);++i)
#define FORrev(i,n) for(i=(n);i>=0;--i)
#define ii pair<ll,ll>
#define vi vector<ll>
#define vii vector<ii>
#define ff first 
#define ss second
#define cd complex<double>
#define vcd vector<cd>
#define ldd long double
#define all(x) (x).begin(),(x).end()

using namespace std;

const short int __PRECISION = 10;

const ll MOD = 1e9+7;
const ll INF = 1e17 + 1101;
const ll LOGN = 17;
const ll MAXN = 2e5+5;
const ll ROOTN = 320;

const ldd PI = acos(-1);
const ldd EPS = 1e-7;

int main()
{
	/*
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	*/


	int N,M,K;
	int i,j,k,mask;
	ll ans = 0;

	cin>>N>>M>>K;

	vi g[N+1];
	ll dp[N+1][(1<<K)],col[N+1];

	FORe(i,N)
	{
		cin>>j;
		col[i] = j-1;
	}

	FOR(i,M)
	{
		cin>>j>>k;
		if(col[j] != col[k])
		{
			g[j].pb(k);
			g[k].pb(j);
		}
	}

	FOR(i,N+1)
		FOR(mask,(1<<K))
			dp[i][mask] = 0;

	FORe(i,N)
		dp[i][(1<<col[i])] = 1;
	
	FOR(mask,(1<<K))
		FORe(i,N)
			if(mask&(1<<col[i]))
				for(ll b : g[i])
					if(((1<<col[b])&(mask)) == 0)
						dp[b][(mask | (1<<col[b]))] +=	dp[i][mask];

	FORe(i,N)
		FOR(mask,(1<<K))
		{
			if(__builtin_popcount(mask) > 1)
				ans += dp[i][mask];
			//cout<<"dp["<<i<<"]["<<(bitset<5>(mask).to_string())<<"] = "<<dp[i][mask]<<endl;
		}

	cout<<ans;
	return 0;
}   
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...