답안 #473370

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
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';
}

# 결과 실행 시간 메모리 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
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3085 ms 91748 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 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 -
# 결과 실행 시간 메모리 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 -