답안 #689966

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
689966 2023-01-29T22:38:15 Z NK_ Paths (BOI18_paths) C++17
100 / 100
436 ms 66220 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(const 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;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 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 1 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
# 결과 실행 시간 메모리 Grader output
1 Correct 64 ms 4232 KB Output is correct
2 Correct 51 ms 3836 KB Output is correct
3 Correct 297 ms 47432 KB Output is correct
4 Correct 124 ms 7172 KB Output is correct
5 Correct 79 ms 6744 KB Output is correct
6 Correct 229 ms 33260 KB Output is correct
7 Correct 320 ms 47324 KB Output is correct
8 Correct 320 ms 48092 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 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 1 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 64 ms 4232 KB Output is correct
12 Correct 51 ms 3836 KB Output is correct
13 Correct 297 ms 47432 KB Output is correct
14 Correct 124 ms 7172 KB Output is correct
15 Correct 79 ms 6744 KB Output is correct
16 Correct 229 ms 33260 KB Output is correct
17 Correct 320 ms 47324 KB Output is correct
18 Correct 320 ms 48092 KB Output is correct
19 Correct 64 ms 4228 KB Output is correct
20 Correct 52 ms 3928 KB Output is correct
21 Correct 344 ms 47432 KB Output is correct
22 Correct 100 ms 7296 KB Output is correct
23 Correct 106 ms 6684 KB Output is correct
24 Correct 229 ms 33180 KB Output is correct
25 Correct 312 ms 47424 KB Output is correct
26 Correct 309 ms 48008 KB Output is correct
27 Correct 69 ms 3824 KB Output is correct
28 Correct 90 ms 5856 KB Output is correct
29 Correct 426 ms 66220 KB Output is correct
30 Correct 292 ms 34880 KB Output is correct
31 Correct 296 ms 35020 KB Output is correct
32 Correct 436 ms 66208 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 212 KB Output is correct
39 Correct 0 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 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 33 ms 1436 KB Output is correct
3 Correct 18 ms 1420 KB Output is correct
4 Correct 74 ms 16132 KB Output is correct
5 Correct 58 ms 16648 KB Output is correct
6 Correct 166 ms 34832 KB Output is correct
7 Correct 24 ms 1364 KB Output is correct
8 Correct 103 ms 22276 KB Output is correct
9 Correct 75 ms 22992 KB Output is correct
10 Correct 91 ms 22856 KB Output is correct
11 Correct 87 ms 17988 KB Output is correct
12 Correct 102 ms 26848 KB Output is correct
13 Correct 79 ms 18064 KB Output is correct
14 Correct 134 ms 34764 KB Output is correct
15 Correct 120 ms 34896 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 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 212 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