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>
using namespace std;
#define IOS cin.tie(nullptr)->sync_with_stdio(0),cin.exceptions(cin.failbit);
#define lb(x) (x)&-(x)
#define all(x) (x).begin(),(x).end()
#define ll long long
constexpr int maxN=3e5+5;
int n,m,k,col[maxN];
ll dp[maxN][1<<5],ans;
vector<int> adj[maxN];
int main(){
cin>>n>>m>>k;
for(int i = 1;i<=n;i++)cin>>col[i],--col[i],dp[i][1<<col[i]]=1;
for(int a,b;m--;)cin>>a>>b,adj[adj[b].emplace_back(a)].emplace_back(b);
for(int mask = 0;mask<1<<k;mask++)for(int i = 1;i<=n;i++)if(mask>>col[i]&1)for(int j:adj[i])dp[i][mask]+=dp[j][mask^(1<<col[i])];
for(int mask = 0;mask<1<<k;mask++)for(int i = 1;i<=n;i++)if(__builtin_popcount(mask)>1)ans+=dp[i][mask];
cout<<ans;
}
# | 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... |