이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
#define NOT_STONKS ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
using namespace std;
const int maxn = 3e5 + 10; //4e6 + 10; //3e5 + 10;
const int mod = 1e9 + 7; //998244353;
typedef long long ll;
ll n, m, k, c[maxn], dp[50][maxn];
vector<int> G[maxn];
int main() {
NOT_STONKS;
cin >> n >> m >> k;
for (int i = 1; i <= n; i++) cin >> c[i], c[i]--;
for (int i = 0; i < m; i++) {
int u, v;
cin >> u >> v;
G[u].push_back(v);
G[v].push_back(u);
}
for (int i = 1; i <= n; i++) dp[1 << c[i]][i] = 1;
for (int mask = 1; mask < (1 << k); mask++)
for (int i = 1; i <= n; i++)
for (int u : G[i])
dp[mask][i] += dp[mask ^ (1 << c[i])][u];
ll ans = 0;
for (int mask = 0; mask < (1 << k); mask++)
for (int i = 1; i <= n; i++) if (__builtin_popcount(mask) > 1)
ans += dp[mask][i];
cout << ans << endl;
return 0;
}
# | 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... |