# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1034643 | anango | Paths (BOI18_paths) | C++17 | 387 ms | 62292 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>
#define int long long
using namespace std;
int INF = 1LL<<30;
signed main() {
#ifdef ONLINE_JUDGE
ios_base::sync_with_stdio(false);
cin.tie(NULL);
#endif //fast IO
int n,m,k; cin >> n >> m >> k;
vector<vector<int>> adjlist(n);
vector<int> col(n); for (int i=0; i<n; i++) {cin >> col[i]; col[i]--;}
for (int i=0; i<m; i++) {
int u,v; cin >> u >> v; u--; v--;
adjlist[u].push_back(v); adjlist[v].push_back(u);
}
int dp[n][1<<k];
for (int i=0; i<n; i++) {
for (int j=0; j<1<<k; j++) {
dp[i][j] = 0;
}
}
//dp[i][j] = number of paths with this bitmask of colours used, ending in this vertex
for (int i=0; i<n; i++) {
dp[i][1<<col[i]]++;
}
for (int mask=1; mask<1<<k; mask++) {
for (int i=0; i<n; i++) {
if (mask&(1<<col[i])==0) continue;
for (int j:adjlist[i]) {
dp[i][mask]+=dp[j][mask^(1<<col[i])];
}
}
}
int su=0;
for (int i=0; i<n; i++) {
for (int j=0; j<1<<k; j++) {
su+=dp[i][j];
}
}
cout << su-n << endl;
}
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... |