Submission #473370

# Submission time Handle Problem Language Result Execution time Memory
473370 2021-09-15T12:51:58 Z elgamalsalman Paths (BOI18_paths) C++14
23 / 100
3000 ms 91748 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;

ll dp[350050][32];
int n, m, k, colours[350050];
vvi adj;

ll dfs(int u, int mask) {
  if (dp[u][mask] != -1) return dp[u][mask];

  mask |= (1 << colours[u]);
  ll pathsCount = 0;
  for (int v : adj[u]) {
    if ((1 << colours[v]) & mask) continue;
    pathsCount += 1 + dfs(v, mask);
  }

  return dp[u][mask] = pathsCount;
}

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

  cin >> n >> m >> k;
  adj.assign(n + 20, vi());
  for (int i = 0; i < n; i++) {
    cin >> colours[i];
    colours[i]--;
  }

  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    a--; b--;
    adj[a].push_back(b);
    adj[b].push_back(a);
  }

  memset(dp, -1, sizeof dp);
  ll ans = 0;
  for (int i = 0; i < n; i++) {
    ans += dfs(i, 0);
  }

  cout << ans << '\n';
}

# Verdict Execution time Memory Grader output
1 Correct 40 ms 87876 KB Output is correct
2 Correct 40 ms 87876 KB Output is correct
3 Correct 40 ms 87988 KB Output is correct
4 Correct 41 ms 87960 KB Output is correct
5 Correct 39 ms 87868 KB Output is correct
6 Correct 41 ms 87884 KB Output is correct
7 Correct 40 ms 87940 KB Output is correct
8 Correct 41 ms 87924 KB Output is correct
9 Correct 41 ms 87984 KB Output is correct
10 Correct 41 ms 87884 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 3085 ms 91748 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 40 ms 87876 KB Output is correct
2 Correct 40 ms 87876 KB Output is correct
3 Correct 40 ms 87988 KB Output is correct
4 Correct 41 ms 87960 KB Output is correct
5 Correct 39 ms 87868 KB Output is correct
6 Correct 41 ms 87884 KB Output is correct
7 Correct 40 ms 87940 KB Output is correct
8 Correct 41 ms 87924 KB Output is correct
9 Correct 41 ms 87984 KB Output is correct
10 Correct 41 ms 87884 KB Output is correct
11 Execution timed out 3085 ms 91748 KB Time limit exceeded
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 39 ms 87960 KB Output is correct
2 Execution timed out 3075 ms 89040 KB Time limit exceeded
3 Halted 0 ms 0 KB -