Submission #578782

# Submission time Handle Problem Language Result Execution time Memory
578782 2022-06-18T01:51:22 Z thiago_bastos Paths (BOI18_paths) C++17
100 / 100
473 ms 172448 KB
#include <bits/stdc++.h>

using namespace std;

using i64 = long long;
using u64 = unsigned long long;
using ld = long double;
using ii = pair<int, int>;

const int N = 3e5 + 10;
const int M = 32;

int c[N], n, m, k;
i64 dp[2][N][M], ans;

vector<int> g[N];

void solve() {
	cin >> n >> m >> k;

	for(int i = 0; i < n; ++i) {
		cin >> c[i];
		--c[i];
		dp[0][i][1 << c[i]] = 1;
	}

	for(int i = 0; i < m; ++i) {
		int u, v;
		cin >> u >> v;
		--u, --v;
		g[u].push_back(v);
		g[v].push_back(u);
	}
	
	for(int i = 1; i < k; ++i) {

		for(int u = 0; u < n; ++u)
		for(int j = 0; j < (1 << k); ++j)
			dp[1][u][j] = 0;

		for(int u = 0; u < n; ++u) {		
			for(int v : g[u]) {
				if(c[u] == c[v]) continue;
				for(int j = 0; j < (1 << k); ++j) {
					int a = 1 << c[u], b = 1 << c[v];
					if((a & ~j) || (b & j)) continue;
					dp[1][v][(1 << c[v]) | j] += dp[0][u][j];
				}
			}
		}

		for(int u = 0; u < n; ++u) {
			for(int j = 0; j < (1 << k); ++j) {
				dp[0][u][j] = dp[1][u][j];
				ans += dp[1][u][j];
			}
		}
	}
	
	cout << ans << '\n';
}

int main() {
	ios_base :: sync_with_stdio(false);
	cin.tie(0);
	int t = 1;
	//cin >> t;
	while(t--) solve();
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 4 ms 7376 KB Output is correct
2 Correct 4 ms 7392 KB Output is correct
3 Correct 4 ms 7376 KB Output is correct
4 Correct 4 ms 7380 KB Output is correct
5 Correct 5 ms 7380 KB Output is correct
6 Correct 4 ms 7376 KB Output is correct
7 Correct 4 ms 7380 KB Output is correct
8 Correct 4 ms 7380 KB Output is correct
9 Correct 4 ms 7380 KB Output is correct
10 Correct 4 ms 7380 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 77 ms 16332 KB Output is correct
2 Correct 67 ms 13612 KB Output is correct
3 Correct 326 ms 171752 KB Output is correct
4 Correct 96 ms 30284 KB Output is correct
5 Correct 88 ms 22752 KB Output is correct
6 Correct 226 ms 119448 KB Output is correct
7 Correct 328 ms 171596 KB Output is correct
8 Correct 341 ms 172448 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 7376 KB Output is correct
2 Correct 4 ms 7392 KB Output is correct
3 Correct 4 ms 7376 KB Output is correct
4 Correct 4 ms 7380 KB Output is correct
5 Correct 5 ms 7380 KB Output is correct
6 Correct 4 ms 7376 KB Output is correct
7 Correct 4 ms 7380 KB Output is correct
8 Correct 4 ms 7380 KB Output is correct
9 Correct 4 ms 7380 KB Output is correct
10 Correct 4 ms 7380 KB Output is correct
11 Correct 77 ms 16332 KB Output is correct
12 Correct 67 ms 13612 KB Output is correct
13 Correct 326 ms 171752 KB Output is correct
14 Correct 96 ms 30284 KB Output is correct
15 Correct 88 ms 22752 KB Output is correct
16 Correct 226 ms 119448 KB Output is correct
17 Correct 328 ms 171596 KB Output is correct
18 Correct 341 ms 172448 KB Output is correct
19 Correct 78 ms 16460 KB Output is correct
20 Correct 63 ms 13600 KB Output is correct
21 Correct 339 ms 171712 KB Output is correct
22 Correct 99 ms 30288 KB Output is correct
23 Correct 80 ms 22784 KB Output is correct
24 Correct 233 ms 119480 KB Output is correct
25 Correct 335 ms 171672 KB Output is correct
26 Correct 321 ms 172436 KB Output is correct
27 Correct 83 ms 13656 KB Output is correct
28 Correct 113 ms 18684 KB Output is correct
29 Correct 459 ms 171708 KB Output is correct
30 Correct 325 ms 93004 KB Output is correct
31 Correct 306 ms 92884 KB Output is correct
32 Correct 473 ms 171792 KB Output is correct
33 Correct 5 ms 7380 KB Output is correct
34 Correct 4 ms 7372 KB Output is correct
35 Correct 4 ms 7380 KB Output is correct
36 Correct 4 ms 7380 KB Output is correct
37 Correct 4 ms 7380 KB Output is correct
38 Correct 4 ms 7380 KB Output is correct
39 Correct 5 ms 7380 KB Output is correct
40 Correct 4 ms 7424 KB Output is correct
41 Correct 4 ms 7380 KB Output is correct
42 Correct 4 ms 7380 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 7380 KB Output is correct
2 Correct 51 ms 9420 KB Output is correct
3 Correct 25 ms 9420 KB Output is correct
4 Correct 88 ms 61936 KB Output is correct
5 Correct 82 ms 62660 KB Output is correct
6 Correct 219 ms 61976 KB Output is correct
7 Correct 31 ms 9584 KB Output is correct
8 Correct 139 ms 62004 KB Output is correct
9 Correct 113 ms 62696 KB Output is correct
10 Correct 125 ms 62532 KB Output is correct
11 Correct 126 ms 35512 KB Output is correct
12 Correct 171 ms 49356 KB Output is correct
13 Correct 144 ms 35696 KB Output is correct
14 Correct 230 ms 62032 KB Output is correct
15 Correct 252 ms 62072 KB Output is correct
16 Correct 4 ms 7380 KB Output is correct
17 Correct 4 ms 7372 KB Output is correct
18 Correct 4 ms 7380 KB Output is correct
19 Correct 4 ms 7376 KB Output is correct
20 Correct 4 ms 7380 KB Output is correct
21 Correct 4 ms 7376 KB Output is correct
22 Correct 5 ms 7380 KB Output is correct
23 Correct 5 ms 7380 KB Output is correct
24 Correct 4 ms 7380 KB Output is correct
25 Correct 4 ms 7380 KB Output is correct