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;
int main() {
int n, m, k;
cin >> n >> m >> k;
int colors[n];
for(int i = 0; i < n; i++){
cin >> colors[i];
colors[i]--;
}
vector<int> adj[n];
for(int i = 0; i < m; i++){
int a, b;
cin >> a >> b;
a--;
b--;
adj[a].push_back(b);
adj[b].push_back(a);
}
vector<int> order(k);
for(int i = 0; i < k; i++){
order[i] = i;
}
long long res = 0;
vector<long long> dp(n);
vector<long long> next(n);
do {
for(int i = 0; i < n; i++){
if(colors[i] == order[0]){
dp[i] = 1;
}
else{
dp[i] = 0;
}
}
for(int i = 1; i < k; i++){
for(int j = 0; j < n; j++){
long long x = 0;
if(colors[j] == order[i]){
for(int y : adj[j]){
x += dp[y];
}
}
next[j] = x;
}
swap(dp, next);
if(is_sorted(order.begin() + i + 1, order.end())){
for(int j = 0; j < n; j++){
res += dp[j];
}
}
}
} while (next_permutation(order.begin(), order.end()));
cout << res << "\n";
}
# | 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... |