# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
100155 | tushar_2658 | Paths (BOI18_paths) | C++14 | 708 ms | 172544 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;
using ll = long long;
const int maxn = 3e5 + 5;
int arr[maxn];
vector<int> edges[maxn];
int n, m, k;
ll dp[1 << 6][maxn];
ll call(int mask, int node){
if(dp[mask][node] != -1)return dp[mask][node];
int ans = 1;
for(auto i : edges[node]){
if((mask >> arr[i]) & 1)continue;
else {
ans += call(mask ^ (1 << arr[i]), i);
}
}return dp[mask][node] = ans;
}
int main(){
scanf("%d %d %d", &n, &m, &k);
for(int i=1; i<=n; i++){
scanf("%d", &arr[i]);
//--arr[i];
}
for(int i=1; i<=m; i++){
int x, y;
scanf("%d %d", &x, &y);
edges[x].emplace_back(y);
edges[y].emplace_back(x);
}
memset(dp, -1, sizeof dp);
ll ans = 0, mask = 0;
for(int i=1; i<=n; i++){
ans += call((mask ^ (1 << arr[i])), i);
}cout<<ans-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... |