Submission #689970

# Submission time Handle Problem Language Result Execution time Memory
689970 2023-01-29T22:44:57 Z NK_ Paths (BOI18_paths) C++17
100 / 100
600 ms 105504 KB
// Success consists of going from failure to failure without loss of enthusiasm
#include <bits/stdc++.h>

using namespace std;

#define nl '\n'

using ll = int64_t;

int main() {
	cin.tie(0)->sync_with_stdio(0);
	
	int N, M, K; cin >> N >> M >> K;

	vector<int> A(N); for(auto& x : A) { cin >> x; --x; }

	vector<vector<vector<int>>> adj(N, vector<vector<int>>(K));

	for(int i = 0; i < M; i++) {
		int u, v; cin >> u >> v; --u, --v;
		// cout << u << " " << v << nl;
		adj[u][A[v]].push_back(v);
		adj[v][A[u]].push_back(u);
	}

	vector<vector<ll>> dp(N, vector<ll>(1<<K, 0));

	for(int i = 0; i < N; i++) dp[i][1<<A[i]] = 1;

	int P2 = 1;
	ll ans = 0;
	for(int s = 1; s < (1<<K); s++) {
		if (P2 < s) P2 += P2;
		for(int u = 0; u < N; u++) if (dp[u][s] != 0) {
			if (s != P2) ans += dp[u][s];
			for(int b = 0; b < K; b++) if (((s >> b) & 1) ^ 1) {
				for(const auto &v : adj[u][b]) dp[v][s^(1<<b)] += dp[u][s];
			}
		}
	}
	cout << ans << nl;


    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 85 ms 5184 KB Output is correct
2 Correct 52 ms 3976 KB Output is correct
3 Correct 449 ms 76260 KB Output is correct
4 Correct 104 ms 9468 KB Output is correct
5 Correct 83 ms 7672 KB Output is correct
6 Correct 288 ms 52416 KB Output is correct
7 Correct 434 ms 76284 KB Output is correct
8 Correct 432 ms 77452 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 85 ms 5184 KB Output is correct
12 Correct 52 ms 3976 KB Output is correct
13 Correct 449 ms 76260 KB Output is correct
14 Correct 104 ms 9468 KB Output is correct
15 Correct 83 ms 7672 KB Output is correct
16 Correct 288 ms 52416 KB Output is correct
17 Correct 434 ms 76284 KB Output is correct
18 Correct 432 ms 77452 KB Output is correct
19 Correct 77 ms 5280 KB Output is correct
20 Correct 48 ms 3880 KB Output is correct
21 Correct 439 ms 76272 KB Output is correct
22 Correct 107 ms 9548 KB Output is correct
23 Correct 88 ms 7620 KB Output is correct
24 Correct 290 ms 52420 KB Output is correct
25 Correct 428 ms 76276 KB Output is correct
26 Correct 452 ms 77460 KB Output is correct
27 Correct 58 ms 4008 KB Output is correct
28 Correct 98 ms 7112 KB Output is correct
29 Correct 600 ms 105504 KB Output is correct
30 Correct 426 ms 56364 KB Output is correct
31 Correct 425 ms 57404 KB Output is correct
32 Correct 583 ms 105464 KB Output is correct
33 Correct 0 ms 212 KB Output is correct
34 Correct 0 ms 340 KB Output is correct
35 Correct 0 ms 212 KB Output is correct
36 Correct 0 ms 212 KB Output is correct
37 Correct 0 ms 212 KB Output is correct
38 Correct 0 ms 340 KB Output is correct
39 Correct 0 ms 212 KB Output is correct
40 Correct 0 ms 340 KB Output is correct
41 Correct 0 ms 212 KB Output is correct
42 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 25 ms 1724 KB Output is correct
3 Correct 17 ms 1956 KB Output is correct
4 Correct 117 ms 25596 KB Output is correct
5 Correct 80 ms 24516 KB Output is correct
6 Correct 208 ms 49724 KB Output is correct
7 Correct 19 ms 1492 KB Output is correct
8 Correct 155 ms 35292 KB Output is correct
9 Correct 101 ms 33936 KB Output is correct
10 Correct 128 ms 34888 KB Output is correct
11 Correct 125 ms 26036 KB Output is correct
12 Correct 112 ms 36964 KB Output is correct
13 Correct 122 ms 26312 KB Output is correct
14 Correct 202 ms 49624 KB Output is correct
15 Correct 188 ms 49996 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 340 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 0 ms 340 KB Output is correct
22 Correct 0 ms 340 KB Output is correct
23 Correct 0 ms 340 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 0 ms 212 KB Output is correct