# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1091354 | MateiKing80 | Paths (BOI18_paths) | C++14 | 359 ms | 70884 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>
using namespace std;
int n, m, k;
vector<int> vec[300100];
int color[300100];
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n >> m >> k;
for (int i = 1; i <= n; i ++)
{
cin >> color[i];
color[i] --;
}
for (int i = 1; i <= m; i ++)
{
int u, v;
cin >> u >> v;
vec[u].push_back(v);
vec[v].push_back(u);
}
vector<int> ord((1 << k) - 1);
for(int i = 0; i < ord.size(); i ++)
ord[i] = i + 1;
sort(ord.begin(), ord.end(), [&](int a, int b)
{
return __builtin_popcount(a) <= __builtin_popcount(b);
});
vector<vector<long long>> dp(n + 1, vector<long long>(1 << k));
for (int i = 1; i <= n; i ++)
dp[i][(1 << color[i])] = 1;
for(int msk : ord)
for(int v = 1; v <= n; v ++)
for (int to : vec[v])
{
if (msk >> color[to] & 1)
continue;
dp[to][msk | (1 << color[to])] += dp[v][msk];
}
long long ans = 0;
for (int i = 1; i <= n; i ++)
for (int msk = 1; msk < (1 << k); msk ++)
{
if (__builtin_popcount(msk) < 2)
continue;
ans += dp[i][msk];
}
cout << ans;
}
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... |