Submission #689965

# Submission time Handle Problem Language Result Execution time Memory
689965 2023-01-29T22:37:33 Z NK_ Paths (BOI18_paths) C++17
100 / 100
446 ms 70728 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 = long long;

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<int>> adj(N);

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

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

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

	ll ans = 0;
	for(int s = 1; s < (1<<K); s++) {
		for(int u = 0; u < N; u++) if (dp[u][s] != 0) {
			// cout << "FIN: " << u << " " << s << " " << dp[u][s] << nl;
			if (__builtin_popcount(s) != 1) ans += dp[u][s];
			for(auto v : adj[u]) {
				if ((s >> A[v]) & 1) continue;
				dp[v][s^(1<<A[v])] += dp[u][s];
				// cout << "MOVE: " << v << " " << (s ^ (1<<A[v])) << " " << dp[v][s^(1<<A[v])] << nl;
			}
		}
	}
	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 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 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 70 ms 6988 KB Output is correct
2 Correct 55 ms 6208 KB Output is correct
3 Correct 327 ms 51924 KB Output is correct
4 Correct 95 ms 10724 KB Output is correct
5 Correct 74 ms 10064 KB Output is correct
6 Correct 267 ms 37312 KB Output is correct
7 Correct 323 ms 51788 KB Output is correct
8 Correct 325 ms 52576 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 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 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 70 ms 6988 KB Output is correct
12 Correct 55 ms 6208 KB Output is correct
13 Correct 327 ms 51924 KB Output is correct
14 Correct 95 ms 10724 KB Output is correct
15 Correct 74 ms 10064 KB Output is correct
16 Correct 267 ms 37312 KB Output is correct
17 Correct 323 ms 51788 KB Output is correct
18 Correct 325 ms 52576 KB Output is correct
19 Correct 69 ms 7032 KB Output is correct
20 Correct 54 ms 6100 KB Output is correct
21 Correct 310 ms 51968 KB Output is correct
22 Correct 91 ms 10600 KB Output is correct
23 Correct 76 ms 10012 KB Output is correct
24 Correct 239 ms 37332 KB Output is correct
25 Correct 340 ms 51896 KB Output is correct
26 Correct 333 ms 52572 KB Output is correct
27 Correct 68 ms 6316 KB Output is correct
28 Correct 101 ms 8792 KB Output is correct
29 Correct 426 ms 70628 KB Output is correct
30 Correct 302 ms 39028 KB Output is correct
31 Correct 292 ms 38964 KB Output is correct
32 Correct 446 ms 70728 KB Output is correct
33 Correct 0 ms 212 KB Output is correct
34 Correct 1 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 1 ms 212 KB Output is correct
38 Correct 0 ms 340 KB Output is correct
39 Correct 1 ms 320 KB Output is correct
40 Correct 1 ms 340 KB Output is correct
41 Correct 1 ms 316 KB Output is correct
42 Correct 1 ms 320 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 324 KB Output is correct
2 Correct 36 ms 2124 KB Output is correct
3 Correct 18 ms 2140 KB Output is correct
4 Correct 74 ms 17372 KB Output is correct
5 Correct 57 ms 18116 KB Output is correct
6 Correct 138 ms 36156 KB Output is correct
7 Correct 28 ms 2164 KB Output is correct
8 Correct 104 ms 23612 KB Output is correct
9 Correct 75 ms 24384 KB Output is correct
10 Correct 96 ms 24188 KB Output is correct
11 Correct 100 ms 19208 KB Output is correct
12 Correct 84 ms 28132 KB Output is correct
13 Correct 78 ms 19292 KB Output is correct
14 Correct 144 ms 36116 KB Output is correct
15 Correct 135 ms 36124 KB Output is correct
16 Correct 0 ms 320 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 0 ms 340 KB Output is correct
22 Correct 1 ms 324 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 0 ms 212 KB Output is correct