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 ll long long
#define pb push_back
#define fi first
#define se second
const int mod=998244353, maxn=1e5+5;
int n, m, k, c[maxn], u, v, ans;
vector<int> adj[maxn];
bool vis[maxn];
void dfs(int now, int state, int jml) {
if(!vis[now]&&(((1<<c[now])&state)==0)) {
if(jml==1) {
ans++;
} else {
vis[now]=true;
for(auto nxt:adj[now]) {
dfs(nxt, state|(1<<c[now]), jml-1);
}
}
vis[now]=false;
}
}
int main() {
ios_base::sync_with_stdio(false); cin.tie(NULL);
cin >> n >> m >> k;
for(int i=1; i<=n; i++) cin >> c[i];
while(m--) {
cin >> u >> v;
adj[u].pb(v);
adj[v].pb(u);
}
for(int jml=2; jml<=k; jml++) {
for(int i=1; i<=n; i++) {
dfs(i, 0, jml);
}
}
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... |