답안 #689969

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
689969 2023-01-29T22:43:02 Z NK_ Paths (BOI18_paths) C++17
100 / 100
401 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 = 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<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;
}
# 결과 실행 시간 메모리 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 1 ms 272 KB Output is correct
5 Correct 0 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 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
# 결과 실행 시간 메모리 Grader output
1 Correct 63 ms 4232 KB Output is correct
2 Correct 55 ms 3984 KB Output is correct
3 Correct 305 ms 47432 KB Output is correct
4 Correct 101 ms 7272 KB Output is correct
5 Correct 79 ms 6660 KB Output is correct
6 Correct 212 ms 33308 KB Output is correct
7 Correct 324 ms 47336 KB Output is correct
8 Correct 291 ms 48180 KB Output is correct
# 결과 실행 시간 메모리 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 1 ms 272 KB Output is correct
5 Correct 0 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 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 63 ms 4232 KB Output is correct
12 Correct 55 ms 3984 KB Output is correct
13 Correct 305 ms 47432 KB Output is correct
14 Correct 101 ms 7272 KB Output is correct
15 Correct 79 ms 6660 KB Output is correct
16 Correct 212 ms 33308 KB Output is correct
17 Correct 324 ms 47336 KB Output is correct
18 Correct 291 ms 48180 KB Output is correct
19 Correct 63 ms 4300 KB Output is correct
20 Correct 66 ms 3852 KB Output is correct
21 Correct 321 ms 47432 KB Output is correct
22 Correct 85 ms 7336 KB Output is correct
23 Correct 71 ms 6688 KB Output is correct
24 Correct 210 ms 33256 KB Output is correct
25 Correct 304 ms 47428 KB Output is correct
26 Correct 297 ms 48088 KB Output is correct
27 Correct 66 ms 3916 KB Output is correct
28 Correct 96 ms 5892 KB Output is correct
29 Correct 400 ms 66212 KB Output is correct
30 Correct 296 ms 34756 KB Output is correct
31 Correct 295 ms 35132 KB Output is correct
32 Correct 401 ms 66220 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 0 ms 340 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 32 ms 1364 KB Output is correct
3 Correct 23 ms 1356 KB Output is correct
4 Correct 75 ms 16016 KB Output is correct
5 Correct 52 ms 16716 KB Output is correct
6 Correct 135 ms 34892 KB Output is correct
7 Correct 22 ms 1360 KB Output is correct
8 Correct 102 ms 22228 KB Output is correct
9 Correct 79 ms 22912 KB Output is correct
10 Correct 89 ms 22828 KB Output is correct
11 Correct 80 ms 17956 KB Output is correct
12 Correct 79 ms 26828 KB Output is correct
13 Correct 78 ms 18044 KB Output is correct
14 Correct 133 ms 34804 KB Output is correct
15 Correct 125 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 0 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 0 ms 432 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 0 ms 212 KB Output is correct