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 <iostream>
#include <cstring>
#include <vector>
#include <algorithm>
#include <deque>
#include <set>
#include <utility>
#include <array>
#pragma GCC optimize("Ofast,unroll-loops")
#pragma GCC target("avx2,tune=native")
using namespace std;
#define ALL(x) x.begin(), x.end()
#define ShinLena cin.tie(nullptr)->sync_with_stdio(false);
using ll = long long;
#define N 300005
int n, m, k, c[N];
ll d[2][N][33],z;
array<int, 2> el[N];
int main()
{
ShinLena;
cin >> n >> m >> k;
for (int i = 1; i <= n; ++i) cin >> c[i], d[0][i][1<<--c[i]] = 1;
for (int i = 0; i < m; ++i) cin >> el[i][0] >> el[i][1];
for (int i = 1; i <= k; ++i)
{
for (int j = 1; j <= n; ++j) for (int s = 0; s < (1<<k); ++s) d[i&1][j][s] = 0;
for (int j = 0; j < m; ++j)
{
auto [u, v] = el[j];
for (int J = 2; J--; swap(u, v))
for (int s = 0; s < (1<<k); ++s)
{
ll X = !((s>>c[v])&1)*d[!(i&1)][u][s];
d[i&1][v][s|(1<<c[v])] += X, z += X;
}
}
}
cout << z;
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... |