Submission #930396

# Submission time Handle Problem Language Result Execution time Memory
930396 2024-02-19T14:30:28 Z shmad Paths (BOI18_paths) C++17
100 / 100
547 ms 137896 KB
#pragma GCC optimize("O3", "unroll-loops") // "Ofast" 	
#pragma GCC target("avx2", "bmi", "bmi2", "lzcnt", "popcnt") 

#include <bits/stdc++.h>

#define int long long
#define vt vector
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
#define f first
#define s second
#define dbg(x) cerr << #x << " = " << x << '\n'
#define bit(x, i) ((x) >> (i) & 1)

using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;

const int N = 1e6 + 5, mod = 10056;
const ll inf = 1e18;
const ld eps = 1e-6;

ll add (ll a, ll b) {
	a += b;
	if (a < 0) a += mod;
	if (a >= mod) a -= mod;
	return a;
}

ll mul (ll a, ll b) {
	a *= b;
	if (a >= mod) a %= mod;
	return a;
}

int n, m, k, a[N], dp[N][40];
vt<int> g[N];

void solve () {
	cin >> n >> m >> k;
	for (int i = 1; i <= n; i++) cin >> a[i], a[i]--, dp[i][1 << a[i]]++;
	for (int i = 1; i <= m; i++) {
		int x, y;
		cin >> x >> y;
		g[x].pb(y), g[y].pb(x);
	}
	int ans = 0;
	for (int mask = 0; mask < (1 << k); mask++) {
		for (int i = 1; i <= n; i++) {
			for (int j: g[i]) {
				if (bit(mask, a[j])) continue;
				int nmask = mask ^ (1 << a[j]);
				dp[j][nmask] += dp[i][mask];
			}
		}
	}
	for (int mask = 0; mask < (1 << k); mask++) {
		if (__builtin_popcountll(mask) < 2) continue;
		for (int i = 1; i <= n; i++) ans += dp[i][mask];
	}
	cout << ans;
	cout << '\n';
}

bool testcases = 0;

signed main() {
	cin.tie(0) -> sync_with_stdio(0);
	int test = 1;
	if (testcases) cin >> test;
	for (int cs = 1; cs <= test; cs++) {
		solve();
	}
}
# Verdict Execution time Memory Grader output
1 Correct 8 ms 27228 KB Output is correct
2 Correct 8 ms 27228 KB Output is correct
3 Correct 8 ms 27228 KB Output is correct
4 Correct 8 ms 27268 KB Output is correct
5 Correct 9 ms 27228 KB Output is correct
6 Correct 9 ms 27228 KB Output is correct
7 Correct 8 ms 27228 KB Output is correct
8 Correct 8 ms 27228 KB Output is correct
9 Correct 8 ms 27228 KB Output is correct
10 Correct 8 ms 27228 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 68 ms 39376 KB Output is correct
2 Correct 60 ms 36716 KB Output is correct
3 Correct 286 ms 137164 KB Output is correct
4 Correct 85 ms 48976 KB Output is correct
5 Correct 71 ms 49052 KB Output is correct
6 Correct 255 ms 103544 KB Output is correct
7 Correct 396 ms 137144 KB Output is correct
8 Correct 365 ms 137704 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 27228 KB Output is correct
2 Correct 8 ms 27228 KB Output is correct
3 Correct 8 ms 27228 KB Output is correct
4 Correct 8 ms 27268 KB Output is correct
5 Correct 9 ms 27228 KB Output is correct
6 Correct 9 ms 27228 KB Output is correct
7 Correct 8 ms 27228 KB Output is correct
8 Correct 8 ms 27228 KB Output is correct
9 Correct 8 ms 27228 KB Output is correct
10 Correct 8 ms 27228 KB Output is correct
11 Correct 68 ms 39376 KB Output is correct
12 Correct 60 ms 36716 KB Output is correct
13 Correct 286 ms 137164 KB Output is correct
14 Correct 85 ms 48976 KB Output is correct
15 Correct 71 ms 49052 KB Output is correct
16 Correct 255 ms 103544 KB Output is correct
17 Correct 396 ms 137144 KB Output is correct
18 Correct 365 ms 137704 KB Output is correct
19 Correct 70 ms 39316 KB Output is correct
20 Correct 75 ms 36692 KB Output is correct
21 Correct 369 ms 137100 KB Output is correct
22 Correct 104 ms 48968 KB Output is correct
23 Correct 81 ms 48968 KB Output is correct
24 Correct 225 ms 103460 KB Output is correct
25 Correct 346 ms 137044 KB Output is correct
26 Correct 392 ms 137896 KB Output is correct
27 Correct 81 ms 36620 KB Output is correct
28 Correct 106 ms 40768 KB Output is correct
29 Correct 547 ms 137168 KB Output is correct
30 Correct 363 ms 86732 KB Output is correct
31 Correct 345 ms 87748 KB Output is correct
32 Correct 538 ms 137184 KB Output is correct
33 Correct 10 ms 27228 KB Output is correct
34 Correct 9 ms 27224 KB Output is correct
35 Correct 8 ms 25180 KB Output is correct
36 Correct 9 ms 27228 KB Output is correct
37 Correct 12 ms 23876 KB Output is correct
38 Correct 12 ms 23900 KB Output is correct
39 Correct 10 ms 27228 KB Output is correct
40 Correct 9 ms 25280 KB Output is correct
41 Correct 11 ms 23948 KB Output is correct
42 Correct 12 ms 23900 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 27224 KB Output is correct
2 Correct 48 ms 26856 KB Output is correct
3 Correct 38 ms 26968 KB Output is correct
4 Correct 85 ms 60764 KB Output is correct
5 Correct 59 ms 65220 KB Output is correct
6 Correct 227 ms 64092 KB Output is correct
7 Correct 40 ms 30228 KB Output is correct
8 Correct 131 ms 64208 KB Output is correct
9 Correct 89 ms 64464 KB Output is correct
10 Correct 99 ms 61308 KB Output is correct
11 Correct 90 ms 43720 KB Output is correct
12 Correct 105 ms 54340 KB Output is correct
13 Correct 128 ms 45908 KB Output is correct
14 Correct 236 ms 65000 KB Output is correct
15 Correct 224 ms 64284 KB Output is correct
16 Correct 8 ms 27228 KB Output is correct
17 Correct 8 ms 27228 KB Output is correct
18 Correct 9 ms 27312 KB Output is correct
19 Correct 11 ms 27324 KB Output is correct
20 Correct 10 ms 27248 KB Output is correct
21 Correct 9 ms 27224 KB Output is correct
22 Correct 9 ms 27328 KB Output is correct
23 Correct 11 ms 23944 KB Output is correct
24 Correct 8 ms 27228 KB Output is correct
25 Correct 10 ms 23948 KB Output is correct