Submission #989040

# Submission time Handle Problem Language Result Execution time Memory
989040 2024-05-27T10:44:58 Z AlphaMale06 Paths (BOI18_paths) C++17
100 / 100
289 ms 100432 KB
#include <bits/stdc++.h>

using namespace std;

#define int long long

const int N = 3e5+3;
int dp[N][32];

vector<int> g[N];

signed main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n, m, k;
    cin >> n >> m >> k;
    int col[n];
    for(int i=0; i< n; i++){
        cin >> col[i];
        col[i]--;
        col[i]=1<<col[i];
    }
    for(int i=0; i< m; i++){
        int a, b;
        cin >> a >> b;
        a--; b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    for(int i=0; i< n; i++){
        dp[i][col[i]]=1;
    }
    vector<int> maske[k];
    for(int i=1; i< (1<<k); i++){
        int pcnt = __builtin_popcount(i);
        maske[pcnt-1].push_back(i);
    }
    for(int j=0; j<k; j++){
        for(int i=0; i< n; i++){
            for(int mask : maske[j]){
                for(int to : g[i]){
                    if(col[to] & mask)continue;
                    dp[to][mask+col[to]]+=dp[i][mask];
                }
            }
        }
    }
    int ans=0;
    for(int i=1; i< (1<<k); i++){
        for(int j=0; j< n; j++)ans+=dp[j][i];
    }
    cout << ans-n << '\n';
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 7512 KB Output is correct
2 Correct 2 ms 7516 KB Output is correct
3 Correct 3 ms 7528 KB Output is correct
4 Correct 2 ms 7516 KB Output is correct
5 Correct 2 ms 7516 KB Output is correct
6 Correct 2 ms 7512 KB Output is correct
7 Correct 2 ms 7516 KB Output is correct
8 Correct 3 ms 7516 KB Output is correct
9 Correct 2 ms 7516 KB Output is correct
10 Correct 2 ms 7260 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 59 ms 18772 KB Output is correct
2 Correct 49 ms 17108 KB Output is correct
3 Correct 199 ms 99920 KB Output is correct
4 Correct 67 ms 26524 KB Output is correct
5 Correct 57 ms 26620 KB Output is correct
6 Correct 144 ms 71872 KB Output is correct
7 Correct 192 ms 99872 KB Output is correct
8 Correct 189 ms 100432 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 7512 KB Output is correct
2 Correct 2 ms 7516 KB Output is correct
3 Correct 3 ms 7528 KB Output is correct
4 Correct 2 ms 7516 KB Output is correct
5 Correct 2 ms 7516 KB Output is correct
6 Correct 2 ms 7512 KB Output is correct
7 Correct 2 ms 7516 KB Output is correct
8 Correct 3 ms 7516 KB Output is correct
9 Correct 2 ms 7516 KB Output is correct
10 Correct 2 ms 7260 KB Output is correct
11 Correct 59 ms 18772 KB Output is correct
12 Correct 49 ms 17108 KB Output is correct
13 Correct 199 ms 99920 KB Output is correct
14 Correct 67 ms 26524 KB Output is correct
15 Correct 57 ms 26620 KB Output is correct
16 Correct 144 ms 71872 KB Output is correct
17 Correct 192 ms 99872 KB Output is correct
18 Correct 189 ms 100432 KB Output is correct
19 Correct 58 ms 18576 KB Output is correct
20 Correct 49 ms 16988 KB Output is correct
21 Correct 196 ms 99768 KB Output is correct
22 Correct 72 ms 26704 KB Output is correct
23 Correct 64 ms 26704 KB Output is correct
24 Correct 141 ms 71872 KB Output is correct
25 Correct 191 ms 99920 KB Output is correct
26 Correct 194 ms 100432 KB Output is correct
27 Correct 66 ms 17072 KB Output is correct
28 Correct 86 ms 20820 KB Output is correct
29 Correct 289 ms 99940 KB Output is correct
30 Correct 214 ms 58820 KB Output is correct
31 Correct 197 ms 58944 KB Output is correct
32 Correct 278 ms 99940 KB Output is correct
33 Correct 2 ms 7516 KB Output is correct
34 Correct 2 ms 7516 KB Output is correct
35 Correct 2 ms 7516 KB Output is correct
36 Correct 2 ms 7516 KB Output is correct
37 Correct 2 ms 7388 KB Output is correct
38 Correct 2 ms 7516 KB Output is correct
39 Correct 2 ms 7516 KB Output is correct
40 Correct 2 ms 7516 KB Output is correct
41 Correct 2 ms 7260 KB Output is correct
42 Correct 2 ms 7448 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 7516 KB Output is correct
2 Correct 36 ms 10352 KB Output is correct
3 Correct 18 ms 10396 KB Output is correct
4 Correct 66 ms 38172 KB Output is correct
5 Correct 42 ms 38596 KB Output is correct
6 Correct 93 ms 37968 KB Output is correct
7 Correct 24 ms 10328 KB Output is correct
8 Correct 70 ms 38088 KB Output is correct
9 Correct 63 ms 38600 KB Output is correct
10 Correct 65 ms 38184 KB Output is correct
11 Correct 60 ms 24012 KB Output is correct
12 Correct 85 ms 31100 KB Output is correct
13 Correct 61 ms 24128 KB Output is correct
14 Correct 96 ms 37968 KB Output is correct
15 Correct 97 ms 38228 KB Output is correct
16 Correct 2 ms 7516 KB Output is correct
17 Correct 2 ms 7516 KB Output is correct
18 Correct 2 ms 7516 KB Output is correct
19 Correct 6 ms 7516 KB Output is correct
20 Correct 2 ms 7516 KB Output is correct
21 Correct 3 ms 7516 KB Output is correct
22 Correct 3 ms 7512 KB Output is correct
23 Correct 3 ms 7516 KB Output is correct
24 Correct 2 ms 7516 KB Output is correct
25 Correct 2 ms 7260 KB Output is correct