Submission #689968

# Submission time Handle Problem Language Result Execution time Memory
689968 2023-01-29T22:42:28 Z NK_ Paths (BOI18_paths) C++17
100 / 100
444 ms 66216 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, 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(const auto &v : adj[u]) if (((s >> A[v]) & 1) ^ 1) dp[v][s^(1<<A[v])] += 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 340 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 69 ms 4228 KB Output is correct
2 Correct 53 ms 3916 KB Output is correct
3 Correct 303 ms 47432 KB Output is correct
4 Correct 92 ms 7200 KB Output is correct
5 Correct 70 ms 6732 KB Output is correct
6 Correct 225 ms 33188 KB Output is correct
7 Correct 328 ms 47460 KB Output is correct
8 Correct 315 ms 48012 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 340 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 69 ms 4228 KB Output is correct
12 Correct 53 ms 3916 KB Output is correct
13 Correct 303 ms 47432 KB Output is correct
14 Correct 92 ms 7200 KB Output is correct
15 Correct 70 ms 6732 KB Output is correct
16 Correct 225 ms 33188 KB Output is correct
17 Correct 328 ms 47460 KB Output is correct
18 Correct 315 ms 48012 KB Output is correct
19 Correct 62 ms 4212 KB Output is correct
20 Correct 52 ms 3936 KB Output is correct
21 Correct 316 ms 47488 KB Output is correct
22 Correct 82 ms 7200 KB Output is correct
23 Correct 70 ms 6684 KB Output is correct
24 Correct 200 ms 33364 KB Output is correct
25 Correct 318 ms 47380 KB Output is correct
26 Correct 293 ms 48056 KB Output is correct
27 Correct 69 ms 4044 KB Output is correct
28 Correct 91 ms 5920 KB Output is correct
29 Correct 419 ms 66216 KB Output is correct
30 Correct 277 ms 34868 KB Output is correct
31 Correct 287 ms 35016 KB Output is correct
32 Correct 444 ms 66216 KB Output is correct
33 Correct 0 ms 212 KB Output is correct
34 Correct 0 ms 212 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 1 ms 212 KB Output is correct
39 Correct 1 ms 212 KB Output is correct
40 Correct 0 ms 212 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 33 ms 1460 KB Output is correct
3 Correct 18 ms 1384 KB Output is correct
4 Correct 76 ms 16024 KB Output is correct
5 Correct 60 ms 16768 KB Output is correct
6 Correct 133 ms 34764 KB Output is correct
7 Correct 22 ms 1372 KB Output is correct
8 Correct 107 ms 22192 KB Output is correct
9 Correct 74 ms 23020 KB Output is correct
10 Correct 87 ms 22884 KB Output is correct
11 Correct 88 ms 17996 KB Output is correct
12 Correct 91 ms 26720 KB Output is correct
13 Correct 79 ms 17988 KB Output is correct
14 Correct 151 ms 34764 KB Output is correct
15 Correct 118 ms 34788 KB Output is correct
16 Correct 0 ms 212 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 1 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 0 ms 212 KB Output is correct