# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
863717 | 2023-10-20T18:05:34 Z | alittlemiddle | Paths (BOI18_paths) | C++14 | 312 ms | 486500 KB |
#include <bits/stdc++.h> #define task using namespace std; const int maxn=3e5+4; const int maxk=6; const int BASE=33; int n,m,k,u,v; vector <int> mask[maxk][maxk]; vector <int> adj[maxn]; long long dp[maxn][maxk][BASE]; long long ans=0; int col[maxn]; void input() { cin>>n>>m>>k; for (int i=1;i<=n;i++) { cin>>col[i]; } for (int i=1;i<=m;i++) { cin>>u>>v; adj[u].push_back(v); adj[v].push_back(u); } for (int i=0;i<(1<<k);i++) { int x=0,y=i; while (y>0) {x+=y%2; y/=2;} for (int j=1;j<=k;j++) if (i&(1<<(j-1))) mask[x][j].push_back(i); } } void solve() { for (int i=1;i<=n;i++) { dp[i][1][1<<(col[i]-1)]=1; } for (int i=2;i<=k;i++) { for (int j=1;j<=n;j++) { for (int x:mask[i][col[j]]) { for (int y:adj[j]) dp[j][i][x]+=dp[y][i-1][x^(1<<(col[j]-1))]; ans+=dp[j][i][x]; //cout<<j<<" "<<i<<" "<<x<<" "<<dp[j][i][x]<<"\n"; } } } cout<<ans; } signed main() { if (fopen(task".INP","r")) { freopen(task".INP", "r", stdin); freopen(task".OUT", "w", stdout); } ios_base::sync_with_stdio(0); cin.tie(0); input(); solve(); }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 9564 KB | Output is correct |
2 | Correct | 2 ms | 9564 KB | Output is correct |
3 | Correct | 2 ms | 9564 KB | Output is correct |
4 | Correct | 2 ms | 9564 KB | Output is correct |
5 | Correct | 2 ms | 9564 KB | Output is correct |
6 | Correct | 2 ms | 9564 KB | Output is correct |
7 | Correct | 2 ms | 9564 KB | Output is correct |
8 | Correct | 2 ms | 9564 KB | Output is correct |
9 | Correct | 3 ms | 9564 KB | Output is correct |
10 | Correct | 2 ms | 9564 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 44 ms | 21436 KB | Output is correct |
2 | Correct | 35 ms | 15136 KB | Output is correct |
3 | Correct | 198 ms | 485104 KB | Output is correct |
4 | Correct | 62 ms | 64336 KB | Output is correct |
5 | Correct | 60 ms | 64380 KB | Output is correct |
6 | Correct | 149 ms | 329920 KB | Output is correct |
7 | Correct | 222 ms | 485832 KB | Output is correct |
8 | Correct | 190 ms | 486480 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 9564 KB | Output is correct |
2 | Correct | 2 ms | 9564 KB | Output is correct |
3 | Correct | 2 ms | 9564 KB | Output is correct |
4 | Correct | 2 ms | 9564 KB | Output is correct |
5 | Correct | 2 ms | 9564 KB | Output is correct |
6 | Correct | 2 ms | 9564 KB | Output is correct |
7 | Correct | 2 ms | 9564 KB | Output is correct |
8 | Correct | 2 ms | 9564 KB | Output is correct |
9 | Correct | 3 ms | 9564 KB | Output is correct |
10 | Correct | 2 ms | 9564 KB | Output is correct |
11 | Correct | 44 ms | 21436 KB | Output is correct |
12 | Correct | 35 ms | 15136 KB | Output is correct |
13 | Correct | 198 ms | 485104 KB | Output is correct |
14 | Correct | 62 ms | 64336 KB | Output is correct |
15 | Correct | 60 ms | 64380 KB | Output is correct |
16 | Correct | 149 ms | 329920 KB | Output is correct |
17 | Correct | 222 ms | 485832 KB | Output is correct |
18 | Correct | 190 ms | 486480 KB | Output is correct |
19 | Correct | 44 ms | 23892 KB | Output is correct |
20 | Correct | 44 ms | 17368 KB | Output is correct |
21 | Correct | 226 ms | 485708 KB | Output is correct |
22 | Correct | 62 ms | 64340 KB | Output is correct |
23 | Correct | 60 ms | 64336 KB | Output is correct |
24 | Correct | 162 ms | 330288 KB | Output is correct |
25 | Correct | 192 ms | 485764 KB | Output is correct |
26 | Correct | 225 ms | 486500 KB | Output is correct |
27 | Correct | 37 ms | 17236 KB | Output is correct |
28 | Correct | 54 ms | 29520 KB | Output is correct |
29 | Correct | 244 ms | 486484 KB | Output is correct |
30 | Correct | 161 ms | 251560 KB | Output is correct |
31 | Correct | 164 ms | 251492 KB | Output is correct |
32 | Correct | 312 ms | 486484 KB | Output is correct |
33 | Correct | 2 ms | 9564 KB | Output is correct |
34 | Correct | 2 ms | 9564 KB | Output is correct |
35 | Correct | 2 ms | 9564 KB | Output is correct |
36 | Correct | 2 ms | 9564 KB | Output is correct |
37 | Correct | 2 ms | 9724 KB | Output is correct |
38 | Correct | 2 ms | 9564 KB | Output is correct |
39 | Correct | 3 ms | 9564 KB | Output is correct |
40 | Correct | 2 ms | 9564 KB | Output is correct |
41 | Correct | 2 ms | 9564 KB | Output is correct |
42 | Correct | 2 ms | 9560 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 9564 KB | Output is correct |
2 | Correct | 15 ms | 10828 KB | Output is correct |
3 | Correct | 13 ms | 10588 KB | Output is correct |
4 | Correct | 53 ms | 168616 KB | Output is correct |
5 | Correct | 47 ms | 169164 KB | Output is correct |
6 | Correct | 101 ms | 168532 KB | Output is correct |
7 | Correct | 13 ms | 10588 KB | Output is correct |
8 | Correct | 70 ms | 168812 KB | Output is correct |
9 | Correct | 74 ms | 169164 KB | Output is correct |
10 | Correct | 68 ms | 169024 KB | Output is correct |
11 | Correct | 57 ms | 89548 KB | Output is correct |
12 | Correct | 71 ms | 129452 KB | Output is correct |
13 | Correct | 62 ms | 89844 KB | Output is correct |
14 | Correct | 99 ms | 168532 KB | Output is correct |
15 | Correct | 99 ms | 168540 KB | Output is correct |
16 | Correct | 2 ms | 9560 KB | Output is correct |
17 | Correct | 2 ms | 9580 KB | Output is correct |
18 | Correct | 2 ms | 9564 KB | Output is correct |
19 | Correct | 2 ms | 9564 KB | Output is correct |
20 | Correct | 2 ms | 9564 KB | Output is correct |
21 | Correct | 2 ms | 9564 KB | Output is correct |
22 | Correct | 2 ms | 9724 KB | Output is correct |
23 | Correct | 2 ms | 9564 KB | Output is correct |
24 | Correct | 2 ms | 9564 KB | Output is correct |
25 | Correct | 2 ms | 9720 KB | Output is correct |