Submission #348989

# Submission time Handle Problem Language Result Execution time Memory
348989 2021-01-16T09:33:10 Z blue Paths (BOI18_paths) C++17
0 / 100
10 ms 8172 KB
#include <iostream>
#include <vector>
using namespace std;

int N, M, K;
int col[300001];
vector<int> edge[300001];

vector< vector<int> > dp;
int curr;

int count1[33];

void dfs(int u, int mask)
{
    if(mask & (1 << col[u])) return;
    mask += (1 << col[u]);

    dp[curr][mask - (1 << col[curr])] += 1;

    if(count1[mask] < 3)
        for(int v: edge[u]) dfs(v, mask);

}

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

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

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

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

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

    for(curr = 1; curr <= N; curr++) dfs(curr, 0);

    // for(int i = 1; i <= N; i++)
    // {
    //     for(int j = 0; j < (1 << K); j++) cout << dp[i][j] << ' ';
    //     cout << '\n';
    // }

    long long res = 0;

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

    cout << res - N << '\n';
}
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 7404 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 10 ms 8172 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 7404 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 7404 KB Output is correct
2 Incorrect 6 ms 7532 KB Output isn't correct
3 Halted 0 ms 0 KB -