답안 #348990

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
348990 2021-01-16T09:35:09 Z blue Paths (BOI18_paths) C++17
0 / 100
3000 ms 42732 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 <= M; 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';
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 5 ms 7404 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 620 ms 13804 KB Output is correct
2 Correct 2593 ms 13340 KB Output is correct
3 Correct 584 ms 42732 KB Output is correct
4 Correct 286 ms 16492 KB Output is correct
5 Correct 239 ms 16512 KB Output is correct
6 Execution timed out 3086 ms 33376 KB Time limit exceeded
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 5 ms 7404 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 7404 KB Output is correct
2 Incorrect 827 ms 9324 KB Output isn't correct
3 Halted 0 ms 0 KB -