Submission #104788

# Submission time Handle Problem Language Result Execution time Memory
104788 2019-04-09T09:19:54 Z daili Paths (BOI18_paths) C++14
23 / 100
563 ms 47588 KB
#include <bits/stdc++.h>

using namespace std;

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;
}

int 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;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 3 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 3 ms 412 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 123 ms 4264 KB Output is correct
2 Correct 100 ms 3944 KB Output is correct
3 Correct 563 ms 47588 KB Output is correct
4 Correct 182 ms 7292 KB Output is correct
5 Correct 159 ms 6860 KB Output is correct
6 Incorrect 405 ms 33340 KB Output isn't correct
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 3 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 3 ms 412 KB Output is correct
11 Correct 123 ms 4264 KB Output is correct
12 Correct 100 ms 3944 KB Output is correct
13 Correct 563 ms 47588 KB Output is correct
14 Correct 182 ms 7292 KB Output is correct
15 Correct 159 ms 6860 KB Output is correct
16 Incorrect 405 ms 33340 KB Output isn't correct
17 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 384 KB Output is correct
2 Incorrect 44 ms 1536 KB Output isn't correct
3 Halted 0 ms 0 KB -