Submission #430805

# Submission time Handle Problem Language Result Execution time Memory
430805 2021-06-17T05:29:17 Z wind_reaper Paths (BOI18_paths) C++17
100 / 100
760 ms 97300 KB
#include <bits/stdc++.h>
/*
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
*/

using namespace std;
// using namespace __gnu_pbds;
using namespace chrono;

// mt19937 rng((int) std::chrono::steady_clock::now().time_since_epoch().count());
/*
template <class T> using ordered_set = tree <T, null_type, less <T>, rb_tree_tag, tree_order_statistics_node_update>;
*/

//***************** CONSTANTS *****************

const int MXN = 300001;

//***************** GLOBAL VARIABLES *****************

int N, M, K;
vector<int> g[MXN];
int a[MXN];
int64_t dp[MXN][32];

//***************** AUXILIARY STRUCTS *****************



//***************** MAIN BODY *****************


void solve(){
	cin >> N >> M >> K;

	for(int i = 1; i <= N; i++){
		cin >> a[i];
		--a[i];
	}

	for(int i = 0; i < M; i++){
		int u, v;
		cin >> u >> v;
		g[u].push_back(v);
		g[v].push_back(u);
	}

	int64_t ans = 0;

	for(int mask = 1; mask < (1 << K); mask++){
		for(int u = 1; u <= N; u++){
			if(!(mask & (1 << a[u])))
				continue;
			if(__builtin_popcount(mask) == 1) dp[u][mask]++;
			for(int v : g[u])
				if(a[u] != a[v])
					dp[u][mask] += dp[v][mask ^ (1 << a[u])];

			ans += dp[u][mask]; 
		}
	}

	cout << ans - N << '\n';
}

//***************** *****************

int32_t main(){
	ios_base::sync_with_stdio(NULL);
	cin.tie(NULL);

	#ifdef LOCAL
		auto begin = high_resolution_clock::now();
	#endif

	int tc = 1;
	// cin >> tc; 
	for (int t = 0; t < tc; t++)
		solve();

	#ifdef LOCAL 
		auto end = high_resolution_clock::now();
		cout << fixed << setprecision(4);
		cout << "Execution Time: " << duration_cast<duration<double>>(end - begin).count() << "seconds" << endl;
	#endif

	return 0;
}

/*
If code gives a WA, check for the following : 
1. I/O format

2. Are you clearing all global variables in between tests if multitests are a thing

3. Can you definitively prove the logic
*/
# Verdict Execution time Memory Grader output
1 Correct 5 ms 7500 KB Output is correct
2 Correct 4 ms 7372 KB Output is correct
3 Correct 4 ms 7372 KB Output is correct
4 Correct 5 ms 7372 KB Output is correct
5 Correct 4 ms 7372 KB Output is correct
6 Correct 5 ms 7372 KB Output is correct
7 Correct 4 ms 7372 KB Output is correct
8 Correct 5 ms 7372 KB Output is correct
9 Correct 5 ms 7244 KB Output is correct
10 Correct 5 ms 7244 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 95 ms 12244 KB Output is correct
2 Correct 76 ms 11080 KB Output is correct
3 Correct 505 ms 95736 KB Output is correct
4 Correct 160 ms 22668 KB Output is correct
5 Correct 117 ms 22748 KB Output is correct
6 Correct 337 ms 69436 KB Output is correct
7 Correct 542 ms 96448 KB Output is correct
8 Correct 546 ms 97300 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 7500 KB Output is correct
2 Correct 4 ms 7372 KB Output is correct
3 Correct 4 ms 7372 KB Output is correct
4 Correct 5 ms 7372 KB Output is correct
5 Correct 4 ms 7372 KB Output is correct
6 Correct 5 ms 7372 KB Output is correct
7 Correct 4 ms 7372 KB Output is correct
8 Correct 5 ms 7372 KB Output is correct
9 Correct 5 ms 7244 KB Output is correct
10 Correct 5 ms 7244 KB Output is correct
11 Correct 95 ms 12244 KB Output is correct
12 Correct 76 ms 11080 KB Output is correct
13 Correct 505 ms 95736 KB Output is correct
14 Correct 160 ms 22668 KB Output is correct
15 Correct 117 ms 22748 KB Output is correct
16 Correct 337 ms 69436 KB Output is correct
17 Correct 542 ms 96448 KB Output is correct
18 Correct 546 ms 97300 KB Output is correct
19 Correct 93 ms 15100 KB Output is correct
20 Correct 75 ms 13380 KB Output is correct
21 Correct 533 ms 96536 KB Output is correct
22 Correct 132 ms 22728 KB Output is correct
23 Correct 116 ms 22752 KB Output is correct
24 Correct 366 ms 69404 KB Output is correct
25 Correct 496 ms 96508 KB Output is correct
26 Correct 540 ms 97168 KB Output is correct
27 Correct 88 ms 13380 KB Output is correct
28 Correct 122 ms 16584 KB Output is correct
29 Correct 749 ms 96512 KB Output is correct
30 Correct 443 ms 55340 KB Output is correct
31 Correct 465 ms 55344 KB Output is correct
32 Correct 760 ms 96492 KB Output is correct
33 Correct 5 ms 7372 KB Output is correct
34 Correct 5 ms 7364 KB Output is correct
35 Correct 5 ms 7372 KB Output is correct
36 Correct 5 ms 7368 KB Output is correct
37 Correct 5 ms 7372 KB Output is correct
38 Correct 5 ms 7372 KB Output is correct
39 Correct 5 ms 7364 KB Output is correct
40 Correct 5 ms 7372 KB Output is correct
41 Correct 5 ms 7372 KB Output is correct
42 Correct 5 ms 7244 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 7244 KB Output is correct
2 Correct 36 ms 8608 KB Output is correct
3 Correct 29 ms 8540 KB Output is correct
4 Correct 156 ms 35532 KB Output is correct
5 Correct 92 ms 36228 KB Output is correct
6 Correct 322 ms 35588 KB Output is correct
7 Correct 31 ms 9288 KB Output is correct
8 Correct 229 ms 36932 KB Output is correct
9 Correct 127 ms 37696 KB Output is correct
10 Correct 187 ms 37564 KB Output is correct
11 Correct 175 ms 22964 KB Output is correct
12 Correct 162 ms 30524 KB Output is correct
13 Correct 164 ms 23104 KB Output is correct
14 Correct 350 ms 37060 KB Output is correct
15 Correct 316 ms 37136 KB Output is correct
16 Correct 5 ms 7372 KB Output is correct
17 Correct 5 ms 7372 KB Output is correct
18 Correct 5 ms 7372 KB Output is correct
19 Correct 5 ms 7372 KB Output is correct
20 Correct 5 ms 7360 KB Output is correct
21 Correct 5 ms 7372 KB Output is correct
22 Correct 5 ms 7364 KB Output is correct
23 Correct 5 ms 7364 KB Output is correct
24 Correct 5 ms 7364 KB Output is correct
25 Correct 5 ms 7372 KB Output is correct