Submission #83533

# Submission time Handle Problem Language Result Execution time Memory
83533 2018-11-08T18:53:02 Z Noam527 Paths (BOI18_paths) C++17
100 / 100
656 ms 135916 KB
#include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>
#define endl '\n'
#define fast ios::sync_with_stdio(0), cin.tie(0)
#define debug cout << "ok" << endl
#define finish(x) return cout << x << endl, 0
typedef long long ll;
typedef long double ldb;
const int md = 1e9 + 7, inf = 1e9 + 7;
const ll hs = 199;
const ldb eps = 1e-9, pi = acos(-1);
using namespace std;

int n, m, k;
vector<int> c;
vector<vector<int>> g;
vector<ll> dp[32];

ll calc(int v, int mask) {
	if ((mask & (1 << c[v])) == 0) return 0;
	if (dp[mask][v] != -1) return dp[mask][v];
	if (mask == (1 << c[v])) return dp[mask][v] = 1;
	dp[mask][v] = 0;
	for (const auto &i : g[v]) {
		dp[mask][v] += calc(i, mask ^ (1 << c[v]));
	}
	return dp[mask][v];
}

int main() {
	fast;
	cin >> n >> m >> k;
	c.resize(n);
	for (auto &i : c) cin >> i, --i;
	g.resize(n);
	for (int i = 0, u, v; i < m; i++) {
		cin >> u >> v;
		--u, --v;
		g[u].push_back(v);
		g[v].push_back(u);
	}
	for (int i = 0; i < (1 << k); i++) dp[i].resize(n, -1);
	ll ans = 0;
	for (int i = 0; i < n; i++) for (int mask = 0; mask < (1 << k); mask++)
		if (mask != (mask & -mask))
			ans += calc(i, mask);
	finish(ans);
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 504 KB Output is correct
2 Correct 2 ms 632 KB Output is correct
3 Correct 2 ms 632 KB Output is correct
4 Correct 3 ms 636 KB Output is correct
5 Correct 2 ms 636 KB Output is correct
6 Correct 2 ms 636 KB Output is correct
7 Correct 2 ms 796 KB Output is correct
8 Correct 2 ms 796 KB Output is correct
9 Correct 2 ms 796 KB Output is correct
10 Correct 2 ms 796 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 111 ms 7724 KB Output is correct
2 Correct 78 ms 9436 KB Output is correct
3 Correct 459 ms 45768 KB Output is correct
4 Correct 176 ms 45768 KB Output is correct
5 Correct 119 ms 45768 KB Output is correct
6 Correct 303 ms 46364 KB Output is correct
7 Correct 451 ms 61072 KB Output is correct
8 Correct 440 ms 66364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 504 KB Output is correct
2 Correct 2 ms 632 KB Output is correct
3 Correct 2 ms 632 KB Output is correct
4 Correct 3 ms 636 KB Output is correct
5 Correct 2 ms 636 KB Output is correct
6 Correct 2 ms 636 KB Output is correct
7 Correct 2 ms 796 KB Output is correct
8 Correct 2 ms 796 KB Output is correct
9 Correct 2 ms 796 KB Output is correct
10 Correct 2 ms 796 KB Output is correct
11 Correct 111 ms 7724 KB Output is correct
12 Correct 78 ms 9436 KB Output is correct
13 Correct 459 ms 45768 KB Output is correct
14 Correct 176 ms 45768 KB Output is correct
15 Correct 119 ms 45768 KB Output is correct
16 Correct 303 ms 46364 KB Output is correct
17 Correct 451 ms 61072 KB Output is correct
18 Correct 440 ms 66364 KB Output is correct
19 Correct 103 ms 66364 KB Output is correct
20 Correct 80 ms 66364 KB Output is correct
21 Correct 463 ms 75244 KB Output is correct
22 Correct 128 ms 75244 KB Output is correct
23 Correct 117 ms 75244 KB Output is correct
24 Correct 316 ms 75924 KB Output is correct
25 Correct 461 ms 90744 KB Output is correct
26 Correct 469 ms 95620 KB Output is correct
27 Correct 101 ms 95620 KB Output is correct
28 Correct 135 ms 95620 KB Output is correct
29 Correct 656 ms 123472 KB Output is correct
30 Correct 435 ms 123472 KB Output is correct
31 Correct 481 ms 123472 KB Output is correct
32 Correct 653 ms 135916 KB Output is correct
33 Correct 2 ms 135916 KB Output is correct
34 Correct 2 ms 135916 KB Output is correct
35 Correct 2 ms 135916 KB Output is correct
36 Correct 2 ms 135916 KB Output is correct
37 Correct 2 ms 135916 KB Output is correct
38 Correct 2 ms 135916 KB Output is correct
39 Correct 2 ms 135916 KB Output is correct
40 Correct 2 ms 135916 KB Output is correct
41 Correct 2 ms 135916 KB Output is correct
42 Correct 2 ms 135916 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 135916 KB Output is correct
2 Correct 68 ms 135916 KB Output is correct
3 Correct 26 ms 135916 KB Output is correct
4 Correct 115 ms 135916 KB Output is correct
5 Correct 87 ms 135916 KB Output is correct
6 Correct 274 ms 135916 KB Output is correct
7 Correct 34 ms 135916 KB Output is correct
8 Correct 167 ms 135916 KB Output is correct
9 Correct 109 ms 135916 KB Output is correct
10 Correct 139 ms 135916 KB Output is correct
11 Correct 134 ms 135916 KB Output is correct
12 Correct 132 ms 135916 KB Output is correct
13 Correct 131 ms 135916 KB Output is correct
14 Correct 244 ms 135916 KB Output is correct
15 Correct 272 ms 135916 KB Output is correct
16 Correct 3 ms 135916 KB Output is correct
17 Correct 2 ms 135916 KB Output is correct
18 Correct 2 ms 135916 KB Output is correct
19 Correct 2 ms 135916 KB Output is correct
20 Correct 2 ms 135916 KB Output is correct
21 Correct 2 ms 135916 KB Output is correct
22 Correct 2 ms 135916 KB Output is correct
23 Correct 2 ms 135916 KB Output is correct
24 Correct 3 ms 135916 KB Output is correct
25 Correct 3 ms 135916 KB Output is correct