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 fr(i, n, m) for(int i = (n); i < (m); i ++)
#define pb push_back
#define st first
#define nd second
#define pq priority_queue
#define all(x) begin(x),end(x)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
ll const inf = 1e9;
ll const mod = 1e9 + 7;
ld const eps = 1e-9;
int n, m, k;
int col[300005];
vector<int> g[300005];
int dp[300005][33];
void input(){
memset(dp, -1, sizeof(dp));
cin >> n >> m >> k;
fr(i, 0, n){
cin >> col[i];
--col[i];
}
fr(i, 0, m){
int a, b;
cin >> a >> b;
--a,--b;
g[a].pb(b);
g[b].pb(a);
}
}
ll dfs(int u, int bit){
if(dp[u][bit] != -1) return dp[u][bit];
ll cnt = 0;
for(auto e : g[u]){
if((bit&(1 << col[e])) == 0){
cnt += dfs(e,(bit|(1<<col[e]))) + 1;
}
}
dp[u][bit] = cnt;
return cnt;
}
void solve(){
ll ANS = 0;
fr(i, 0, n){
ANS += dfs(i, (1 << col[i]));
}
cout << ANS << endl;
}
int main()
{
input();
solve();
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... |