# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
135680 | 2019-07-24T09:41:33 Z | Plurm | Paths (BOI18_paths) | C++11 | 919 ms | 25580 KB |
#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
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 9 ms | 7416 KB | Output is correct |
2 | Correct | 8 ms | 7344 KB | Output is correct |
3 | Correct | 8 ms | 7364 KB | Output is correct |
4 | Correct | 8 ms | 7416 KB | Output is correct |
5 | Correct | 10 ms | 7408 KB | Output is correct |
6 | Correct | 10 ms | 7460 KB | Output is correct |
7 | Correct | 8 ms | 7416 KB | Output is correct |
8 | Correct | 8 ms | 7416 KB | Output is correct |
9 | Correct | 8 ms | 7416 KB | Output is correct |
10 | Correct | 8 ms | 7416 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 120 ms | 13944 KB | Output is correct |
2 | Correct | 100 ms | 13176 KB | Output is correct |
3 | Correct | 400 ms | 24980 KB | Output is correct |
4 | Correct | 155 ms | 15696 KB | Output is correct |
5 | Correct | 147 ms | 15272 KB | Output is correct |
6 | Correct | 276 ms | 21728 KB | Output is correct |
7 | Correct | 400 ms | 25072 KB | Output is correct |
8 | Correct | 402 ms | 25580 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 9 ms | 7416 KB | Output is correct |
2 | Correct | 8 ms | 7344 KB | Output is correct |
3 | Correct | 8 ms | 7364 KB | Output is correct |
4 | Correct | 8 ms | 7416 KB | Output is correct |
5 | Correct | 10 ms | 7408 KB | Output is correct |
6 | Correct | 10 ms | 7460 KB | Output is correct |
7 | Correct | 8 ms | 7416 KB | Output is correct |
8 | Correct | 8 ms | 7416 KB | Output is correct |
9 | Correct | 8 ms | 7416 KB | Output is correct |
10 | Correct | 8 ms | 7416 KB | Output is correct |
11 | Correct | 120 ms | 13944 KB | Output is correct |
12 | Correct | 100 ms | 13176 KB | Output is correct |
13 | Correct | 400 ms | 24980 KB | Output is correct |
14 | Correct | 155 ms | 15696 KB | Output is correct |
15 | Correct | 147 ms | 15272 KB | Output is correct |
16 | Correct | 276 ms | 21728 KB | Output is correct |
17 | Correct | 400 ms | 25072 KB | Output is correct |
18 | Correct | 402 ms | 25580 KB | Output is correct |
19 | Correct | 125 ms | 13960 KB | Output is correct |
20 | Correct | 100 ms | 13176 KB | Output is correct |
21 | Correct | 400 ms | 24832 KB | Output is correct |
22 | Correct | 164 ms | 15676 KB | Output is correct |
23 | Correct | 142 ms | 15344 KB | Output is correct |
24 | Correct | 279 ms | 21692 KB | Output is correct |
25 | Correct | 400 ms | 24920 KB | Output is correct |
26 | Correct | 385 ms | 25580 KB | Output is correct |
27 | Correct | 169 ms | 13304 KB | Output is correct |
28 | Correct | 217 ms | 14684 KB | Output is correct |
29 | Correct | 919 ms | 24956 KB | Output is correct |
30 | Correct | 509 ms | 19504 KB | Output is correct |
31 | Correct | 561 ms | 19744 KB | Output is correct |
32 | Correct | 916 ms | 24964 KB | Output is correct |
33 | Correct | 8 ms | 7416 KB | Output is correct |
34 | Correct | 8 ms | 7416 KB | Output is correct |
35 | Correct | 8 ms | 7416 KB | Output is correct |
36 | Correct | 9 ms | 7416 KB | Output is correct |
37 | Correct | 8 ms | 7416 KB | Output is correct |
38 | Correct | 8 ms | 7416 KB | Output is correct |
39 | Correct | 8 ms | 7420 KB | Output is correct |
40 | Correct | 8 ms | 7416 KB | Output is correct |
41 | Correct | 8 ms | 7416 KB | Output is correct |
42 | Correct | 8 ms | 7416 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 8 ms | 7416 KB | Output is correct |
2 | Correct | 182 ms | 9220 KB | Output is correct |
3 | Correct | 38 ms | 9208 KB | Output is correct |
4 | Correct | 112 ms | 13152 KB | Output is correct |
5 | Correct | 84 ms | 13864 KB | Output is correct |
6 | Correct | 871 ms | 13304 KB | Output is correct |
7 | Correct | 61 ms | 9208 KB | Output is correct |
8 | Correct | 230 ms | 13136 KB | Output is correct |
9 | Correct | 139 ms | 13844 KB | Output is correct |
10 | Correct | 157 ms | 13936 KB | Output is correct |
11 | Correct | 494 ms | 11224 KB | Output is correct |
12 | Correct | 396 ms | 12688 KB | Output is correct |
13 | Correct | 483 ms | 11264 KB | Output is correct |
14 | Correct | 875 ms | 13236 KB | Output is correct |
15 | Correct | 832 ms | 13340 KB | Output is correct |
16 | Correct | 8 ms | 7416 KB | Output is correct |
17 | Correct | 8 ms | 7416 KB | Output is correct |
18 | Correct | 8 ms | 7416 KB | Output is correct |
19 | Correct | 8 ms | 7416 KB | Output is correct |
20 | Correct | 8 ms | 7288 KB | Output is correct |
21 | Correct | 8 ms | 7416 KB | Output is correct |
22 | Correct | 8 ms | 7408 KB | Output is correct |
23 | Correct | 8 ms | 7444 KB | Output is correct |
24 | Correct | 8 ms | 7416 KB | Output is correct |
25 | Correct | 8 ms | 7416 KB | Output is correct |