Submission #349000

# Submission time Handle Problem Language Result Execution time Memory
349000 2021-01-16T10:05:11 Z blue Paths (BOI18_paths) C++17
100 / 100
722 ms 52076 KB
#include <iostream>
#include <vector>
using namespace std;

int main()
{
    int N, M, K;
    cin >> N >> M >> K;

    vector<int> col(N+1);
    for(int i = 1; i <= N; i++)
    {
        cin >> col[i];
        col[i] = (1 << (col[i] - 1));
    }

    vector<int> edge[N+1];
    int a, b;
    for(int i = 1; i <= M; i++)
    {
        cin >> a >> b;
        edge[a].push_back(b);
        edge[b].push_back(a);
    }



    vector<int> count1(33);
    count1[0] = 0;
    for(int i = 1; i <= 32; i++) count1[i] = count1[i/2] + (i % 2);


    vector< vector<int> > dp = vector< vector<int> >(N+1, vector<int>((1 << K), 0));


    for(int mask = 1; mask < (1 << K); mask++)
    {
        for(int u = 1; u <= N; u++)
        {
            if(mask & col[u])
            {
                if(count1[mask] == 1) dp[u][mask] = 1;
                else for(int v: edge[u]) dp[u][mask] += dp[v][mask - col[u]];
            }

            // cout << u << ' ' << col[u] << ' ' << bool(mask&1) << bool(mask&2) << bool(mask&4) << ' ' << dp[u][mask] << '\n';
        }
    }


    long long res = 0;

    for(int i = 1; i <= N; i++)
    {
        for(int mask = 0; mask < (1 << K); mask++)
        {
            if(count1[mask] > 1)
                res += dp[i][mask];
        }
    }

    cout << res << '\n';
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 380 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 181 ms 4204 KB Output is correct
2 Correct 198 ms 4116 KB Output is correct
3 Correct 547 ms 38204 KB Output is correct
4 Correct 255 ms 6764 KB Output is correct
5 Correct 252 ms 6764 KB Output is correct
6 Correct 560 ms 26976 KB Output is correct
7 Correct 564 ms 42592 KB Output is correct
8 Correct 574 ms 43116 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 380 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 181 ms 4204 KB Output is correct
12 Correct 198 ms 4116 KB Output is correct
13 Correct 547 ms 38204 KB Output is correct
14 Correct 255 ms 6764 KB Output is correct
15 Correct 252 ms 6764 KB Output is correct
16 Correct 560 ms 26976 KB Output is correct
17 Correct 564 ms 42592 KB Output is correct
18 Correct 574 ms 43116 KB Output is correct
19 Correct 178 ms 7020 KB Output is correct
20 Correct 160 ms 6252 KB Output is correct
21 Correct 528 ms 42476 KB Output is correct
22 Correct 245 ms 10140 KB Output is correct
23 Correct 248 ms 10092 KB Output is correct
24 Correct 415 ms 31328 KB Output is correct
25 Correct 533 ms 42476 KB Output is correct
26 Correct 554 ms 43372 KB Output is correct
27 Correct 153 ms 6124 KB Output is correct
28 Correct 235 ms 8196 KB Output is correct
29 Correct 714 ms 51948 KB Output is correct
30 Correct 519 ms 29796 KB Output is correct
31 Correct 521 ms 29668 KB Output is correct
32 Correct 722 ms 52076 KB Output is correct
33 Correct 1 ms 364 KB Output is correct
34 Correct 1 ms 364 KB Output is correct
35 Correct 1 ms 364 KB Output is correct
36 Correct 1 ms 364 KB Output is correct
37 Correct 1 ms 364 KB Output is correct
38 Correct 1 ms 364 KB Output is correct
39 Correct 1 ms 364 KB Output is correct
40 Correct 1 ms 364 KB Output is correct
41 Correct 1 ms 364 KB Output is correct
42 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 364 KB Output is correct
2 Correct 56 ms 1388 KB Output is correct
3 Correct 50 ms 2304 KB Output is correct
4 Correct 154 ms 14188 KB Output is correct
5 Correct 122 ms 15076 KB Output is correct
6 Correct 308 ms 23788 KB Output is correct
7 Correct 51 ms 2156 KB Output is correct
8 Correct 199 ms 17388 KB Output is correct
9 Correct 148 ms 18276 KB Output is correct
10 Correct 186 ms 18004 KB Output is correct
11 Correct 169 ms 13032 KB Output is correct
12 Correct 192 ms 18808 KB Output is correct
13 Correct 182 ms 13068 KB Output is correct
14 Correct 307 ms 23788 KB Output is correct
15 Correct 311 ms 23792 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 1 ms 512 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Correct 1 ms 364 KB Output is correct