답안 #104789

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
104789 2019-04-09T09:21:02 Z daili Paths (BOI18_paths) C++14
100 / 100
800 ms 74220 KB
#include <bits/stdc++.h>

using namespace std;

#define int long long
long long solve(vector<vector<int>> &adj, int current, int colsUsed, int K, vector<int> &colors, vector<vector<long long>> &dp)
{
    int cnt = 1;

    if (dp[current][colsUsed])
    {
      return dp[current][colsUsed];
    }

    for (auto u : adj[current])
    {
        if ((colsUsed & (1 << colors[u])) == 0)
        {
            cnt += solve(adj, u, colsUsed ^ (1 << colors[u]), K, colors, dp);
        }
    }
    dp[current][colsUsed] = cnt;
    return cnt;
}

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    int n, m, K;
    cin >> n >> m >> K;

    vector<int> cols;
    for (int i = 0; i < n; i++)
    {
        int x;
        cin >> x;
        x--;

        cols.push_back(x);
    }

    vector<vector<int>> graph(n);
    for (int i = 0; i < m; i++)
    {
      int a, b;
      cin >> a >> b;

      a--; b--;
      graph[a].push_back(b);
      graph[b].push_back(a);
    }

    vector<vector<long long>> dp(n+1, vector<long long> (1 << K));

    int res = 0;
    for (int i = 0; i < n; i++)
    {
      res += solve(graph, i, (1 << cols[i]), K, cols, dp);
    }
    cout << res - n;


    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 428 KB Output is correct
2 Correct 3 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 3 ms 384 KB Output is correct
10 Correct 2 ms 428 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 141 ms 7776 KB Output is correct
2 Correct 122 ms 7324 KB Output is correct
3 Correct 674 ms 50764 KB Output is correct
4 Correct 250 ms 10636 KB Output is correct
5 Correct 241 ms 10288 KB Output is correct
6 Correct 444 ms 35876 KB Output is correct
7 Correct 593 ms 55320 KB Output is correct
8 Correct 594 ms 55860 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 428 KB Output is correct
2 Correct 3 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 3 ms 384 KB Output is correct
10 Correct 2 ms 428 KB Output is correct
11 Correct 141 ms 7776 KB Output is correct
12 Correct 122 ms 7324 KB Output is correct
13 Correct 674 ms 50764 KB Output is correct
14 Correct 250 ms 10636 KB Output is correct
15 Correct 241 ms 10288 KB Output is correct
16 Correct 444 ms 35876 KB Output is correct
17 Correct 593 ms 55320 KB Output is correct
18 Correct 594 ms 55860 KB Output is correct
19 Correct 130 ms 10632 KB Output is correct
20 Correct 99 ms 9644 KB Output is correct
21 Correct 599 ms 55320 KB Output is correct
22 Correct 235 ms 14072 KB Output is correct
23 Correct 185 ms 13528 KB Output is correct
24 Correct 450 ms 39864 KB Output is correct
25 Correct 647 ms 55368 KB Output is correct
26 Correct 543 ms 55864 KB Output is correct
27 Correct 134 ms 9684 KB Output is correct
28 Correct 242 ms 12676 KB Output is correct
29 Correct 748 ms 74036 KB Output is correct
30 Correct 666 ms 42700 KB Output is correct
31 Correct 800 ms 42604 KB Output is correct
32 Correct 788 ms 74220 KB Output is correct
33 Correct 2 ms 384 KB Output is correct
34 Correct 3 ms 384 KB Output is correct
35 Correct 2 ms 384 KB Output is correct
36 Correct 2 ms 300 KB Output is correct
37 Correct 2 ms 384 KB Output is correct
38 Correct 2 ms 384 KB Output is correct
39 Correct 2 ms 384 KB Output is correct
40 Correct 2 ms 384 KB Output is correct
41 Correct 3 ms 384 KB Output is correct
42 Correct 2 ms 256 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 432 KB Output is correct
2 Correct 48 ms 2524 KB Output is correct
3 Correct 31 ms 3192 KB Output is correct
4 Correct 168 ms 18544 KB Output is correct
5 Correct 101 ms 18928 KB Output is correct
6 Correct 255 ms 37488 KB Output is correct
7 Correct 34 ms 3200 KB Output is correct
8 Correct 216 ms 24916 KB Output is correct
9 Correct 163 ms 25200 KB Output is correct
10 Correct 221 ms 24940 KB Output is correct
11 Correct 249 ms 20340 KB Output is correct
12 Correct 178 ms 28912 KB Output is correct
13 Correct 158 ms 20340 KB Output is correct
14 Correct 267 ms 37484 KB Output is correct
15 Correct 193 ms 37356 KB Output is correct
16 Correct 3 ms 384 KB Output is correct
17 Correct 3 ms 384 KB Output is correct
18 Correct 2 ms 384 KB Output is correct
19 Correct 3 ms 384 KB Output is correct
20 Correct 3 ms 384 KB Output is correct
21 Correct 2 ms 384 KB Output is correct
22 Correct 2 ms 384 KB Output is correct
23 Correct 2 ms 384 KB Output is correct
24 Correct 2 ms 384 KB Output is correct
25 Correct 2 ms 384 KB Output is correct