이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int mxN = 3e5 + 7;
const int mxK = 39;
int n, m, k, color[mxN], dp[mxN][mxK][2];
vector<int> graph[mxN];
int dfs(int u, int mask, bool sz) {
if (dp[u][mask][sz]) {
return dp[u][mask][sz];
}
if (sz) {
dp[u][mask][sz] = 1;
}
for (auto v : graph[u]) {
if (!(mask & (1 << color[v]))) {
dp[u][mask][sz] += dfs(v, mask | (1 << color[v]), 1);
}
}
return dp[u][mask][sz];
}
int32_t main() {
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> n >> m >> k;
for (int u = 1; u <= n; ++u) {
cin >> color[u];
color[u]--;
}
for (int i = 0; i < m; ++i) {
int u, v;
cin >> u >> v;
graph[u].push_back(v);
graph[v].push_back(u);
}
int ans = 0;
for (int i = 1; i <= n; ++i) {
ans += dfs(i, 1 << color[i], 0);
}
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... |