# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
135680 | Plurm | Paths (BOI18_paths) | C++11 | 919 ms | 25580 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;
vector<int> g[300005];
long long dp[300005];
int col[300005];
vector<int> bckt[8];
int sel[8];
int n;
long long iteratePerm(int k, int c, int lv = 1){
if(lv == c+1){
for(int i = 1; i <= n; i++) dp[i] = 0ll;
for(int u : bckt[sel[1]]) dp[u] = 1ll;
for(int step = 2; step <= c; step++){
for(int u : bckt[sel[step]]){
for(int v : g[u]){
if(col[v] == sel[step-1]) dp[u] += dp[v];
}
}
}
long long sum = 0ll;
for(int i = 1; i <= n; i++){
if(col[i] == sel[c]){
sum += dp[i];
}
}
return sum;
}else{
long long sum = 0ll;
for(int i = 1; i <= k; i++){
bool ok = true;
for(int j = 1; j < lv; j++){
if(sel[j] == i) ok = false;
}
if(ok){
sel[lv] = i;
sum += iteratePerm(k, c, lv+1);
sel[lv] = 0;
}
}
return sum;
}
}
int main(){
int m,k;
scanf("%d%d%d",&n,&m,&k);
for(int i = 1; i <= n; i++){
scanf("%d",col+i);
bckt[col[i]].push_back(i);
}
for(int i = 0; i < m; i++){
int u,v;
scanf("%d%d",&u,&v);
g[u].push_back(v);
g[v].push_back(u);
}
long long ans = 0ll;
for(int i = 2; i <= k; i++){
ans += iteratePerm(k,i);
}
printf("%lld\n",ans);
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... |