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;
typedef long long ll;
typedef pair<int,int> pii;
const int MAXN = 3e5+5;
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
#define mk make_pair
#define pb push_back
#define fr first
#define sc second
int n, m, k, c[MAXN];
ll qtd[10];
vector<int> edges[MAXN], color[10];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> n >> m >> k;
for(int i = 1; i <= n; i++)
cin >> c[i], color[c[i]].pb(i);
while(m--) {
int a, b;
cin >> a >> b;
edges[a].pb(b);
edges[b].pb(a);
}
vector<int> ord;
for(int i = 1; i <= k; i++) ord.pb(i);
do {
vector<ll> dp(n+1);
for(int i = 0; i < k; i++) {
for(auto x : color[ord[i]]) {
if(!i) { dp[x] = 1; qtd[i]++; continue; }
for(auto viz : edges[x])
if(c[viz] == ord[i-1]) dp[x] += dp[viz];
qtd[i] += dp[x];
}
}
} while(next_permutation(all(ord)));
ll ans = 0;
for(int i = k, fat = 1; i > 1; i--, fat *= (k-i))
ans += qtd[i-1] / fat;
cout << ans << "\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... |