답안 #522392

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
522392 2022-02-04T18:34:54 Z LucaDantas Paths (BOI18_paths) C++17
100 / 100
363 ms 56712 KB
#include <bits/stdc++.h>
using namespace std;

constexpr int maxn = 3e5+10, maxk = 5;

int color[maxn], k;

long long dp[1<<maxk][maxn];

bool vis[1<<maxk][maxn];

vector<int> g[maxn];

long long solve(int x, int mask) {
	if(vis[mask][x]) return dp[mask][x];

	vis[mask][x] = 1;
	dp[mask][x] = 1;

	for(int v : g[x])
		if(!(mask & color[v])) dp[mask][x] += solve(v, mask ^ color[v]);

	return dp[mask][x];
}

int main() {
	int n, m; scanf("%d %d %d", &n, &m, &k);
	for(int i = 1; i <= n; i++)
		scanf("%d", &color[i]), color[i] = 1 << (color[i]-1);

	for(int i = 0, a, b; i < m; i++)
		scanf("%d %d", &a, &b), g[a].push_back(b), g[b].push_back(a);

	long long ans = 0;

	for(int i = 1; i <= n; i++)
		ans += solve(i, color[i]) - 1;

	printf("%lld\n", ans);
}

Compilation message

paths.cpp: In function 'int main()':
paths.cpp:27:17: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   27 |  int n, m; scanf("%d %d %d", &n, &m, &k);
      |            ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
paths.cpp:29:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   29 |   scanf("%d", &color[i]), color[i] = 1 << (color[i]-1);
      |   ~~~~~^~~~~~~~~~~~~~~~~
paths.cpp:32:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   32 |   scanf("%d %d", &a, &b), g[a].push_back(b), g[b].push_back(a);
      |   ~~~~~^~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 7500 KB Output is correct
2 Correct 4 ms 7500 KB Output is correct
3 Correct 4 ms 7352 KB Output is correct
4 Correct 4 ms 7372 KB Output is correct
5 Correct 5 ms 7372 KB Output is correct
6 Correct 4 ms 7500 KB Output is correct
7 Correct 5 ms 7476 KB Output is correct
8 Correct 4 ms 7500 KB Output is correct
9 Correct 4 ms 7372 KB Output is correct
10 Correct 4 ms 7372 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 84 ms 11852 KB Output is correct
2 Correct 69 ms 11452 KB Output is correct
3 Correct 302 ms 35664 KB Output is correct
4 Correct 93 ms 12964 KB Output is correct
5 Correct 89 ms 12404 KB Output is correct
6 Correct 193 ms 27956 KB Output is correct
7 Correct 304 ms 35696 KB Output is correct
8 Correct 271 ms 36280 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 7500 KB Output is correct
2 Correct 4 ms 7500 KB Output is correct
3 Correct 4 ms 7352 KB Output is correct
4 Correct 4 ms 7372 KB Output is correct
5 Correct 5 ms 7372 KB Output is correct
6 Correct 4 ms 7500 KB Output is correct
7 Correct 5 ms 7476 KB Output is correct
8 Correct 4 ms 7500 KB Output is correct
9 Correct 4 ms 7372 KB Output is correct
10 Correct 4 ms 7372 KB Output is correct
11 Correct 84 ms 11852 KB Output is correct
12 Correct 69 ms 11452 KB Output is correct
13 Correct 302 ms 35664 KB Output is correct
14 Correct 93 ms 12964 KB Output is correct
15 Correct 89 ms 12404 KB Output is correct
16 Correct 193 ms 27956 KB Output is correct
17 Correct 304 ms 35696 KB Output is correct
18 Correct 271 ms 36280 KB Output is correct
19 Correct 83 ms 11656 KB Output is correct
20 Correct 69 ms 11324 KB Output is correct
21 Correct 306 ms 35716 KB Output is correct
22 Correct 96 ms 12992 KB Output is correct
23 Correct 90 ms 12492 KB Output is correct
24 Correct 280 ms 27952 KB Output is correct
25 Correct 257 ms 35640 KB Output is correct
26 Correct 302 ms 36412 KB Output is correct
27 Correct 89 ms 11480 KB Output is correct
28 Correct 104 ms 13328 KB Output is correct
29 Correct 346 ms 56712 KB Output is correct
30 Correct 279 ms 33780 KB Output is correct
31 Correct 249 ms 31316 KB Output is correct
32 Correct 363 ms 56704 KB Output is correct
33 Correct 4 ms 7480 KB Output is correct
34 Correct 4 ms 7500 KB Output is correct
35 Correct 5 ms 7364 KB Output is correct
36 Correct 4 ms 7372 KB Output is correct
37 Correct 4 ms 7340 KB Output is correct
38 Correct 4 ms 7476 KB Output is correct
39 Correct 4 ms 7480 KB Output is correct
40 Correct 4 ms 7480 KB Output is correct
41 Correct 4 ms 7372 KB Output is correct
42 Correct 4 ms 7344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 7372 KB Output is correct
2 Correct 43 ms 9116 KB Output is correct
3 Correct 28 ms 8764 KB Output is correct
4 Correct 73 ms 16984 KB Output is correct
5 Correct 57 ms 16736 KB Output is correct
6 Correct 104 ms 38380 KB Output is correct
7 Correct 32 ms 8900 KB Output is correct
8 Correct 82 ms 24084 KB Output is correct
9 Correct 62 ms 20400 KB Output is correct
10 Correct 72 ms 19388 KB Output is correct
11 Correct 76 ms 23588 KB Output is correct
12 Correct 53 ms 18620 KB Output is correct
13 Correct 85 ms 19560 KB Output is correct
14 Correct 119 ms 38520 KB Output is correct
15 Correct 94 ms 38468 KB Output is correct
16 Correct 4 ms 7480 KB Output is correct
17 Correct 4 ms 7468 KB Output is correct
18 Correct 4 ms 7352 KB Output is correct
19 Correct 5 ms 7332 KB Output is correct
20 Correct 4 ms 7372 KB Output is correct
21 Correct 4 ms 7480 KB Output is correct
22 Correct 6 ms 7500 KB Output is correct
23 Correct 5 ms 7480 KB Output is correct
24 Correct 5 ms 7340 KB Output is correct
25 Correct 4 ms 7328 KB Output is correct