# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
872818 | tvladm2009 | Paths (BOI18_paths) | C++17 | 357 ms | 110244 KiB |
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>
//#pragma GCC optimize("O3")
//#pragma GCC target("avx,avx2,fma")
#define sz(x) (x).size()
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
using namespace std;
using ll = long long;
using db = long double; // or double, if TL is tight
using str = string;
using ii = pair<int, int>;
using pl = pair<ll, ll>;
using vi = vector<int>;
using vll = vector<ll>;
struct tree {
const int SIGMA = 5;
int n;
vector<vector<int>> L;
vector<int> Cul;
vector<vector<int64_t>> DP;
tree(int N, vector<int> c) : n(N), L(N), DP(N + 1, vector<int64_t>(1 << SIGMA, 0)), Cul(c) {}
void add_edge(int x, int y) {
L[x].push_back(y);
L[y].push_back(x);
}
int64_t solve(int k) {
// for(int i = 0; i < n; i++)
// cout << Cul[i] << " ";
// cout << "\n";
int64_t res = 0;
for(int mask = 1; mask < (1 << k); ++mask) {
for(int i = 0; i < n; ++i) {
if(mask & (1 << Cul[i])) {
if(mask ^ (1 << Cul[i]))
for(auto v : L[i])
DP[i][mask] += DP[v][mask ^ (1 << Cul[i])];
else DP[i][mask] = 1;
}
res += DP[i][mask];
}
}
return res;
}
};
int main() {
cin.tie(0);
ios_base::sync_with_stdio(0);
int n, m, k;
cin >> n >> m >> k;
vector<int> c(n);
for(int i = 0; i < n; ++i) {
cin >> c[i];
--c[i];
}
tree T(n, c);
for(int i = 0; i < m; ++i) {
int x, y;
cin >> x >> y;
--x;
--y;
T.add_edge(x, y);
}
cout << T.solve(k) - n << "\n";
return 0;
}
Compilation message (stderr)
# | 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... |