Submission #1359675

#TimeUsernameProblemLanguageResultExecution timeMemory
1359675blackscreen1Paths (BOI18_paths)C++20
100 / 100
580 ms27880 KiB
#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;
typedef tree<long long, null_type, less<long long>, rb_tree_tag,
             tree_order_statistics_node_update>
    ordered_set;
typedef tree<long long, null_type, less_equal<long long>, rb_tree_tag,
             tree_order_statistics_node_update>
    ordered_multiset;
#define ll long long
#define iloop(m, h) for (auto i = m; i != h; i += (m < h ? 1 : -1))
#define jloop(m, h) for (auto j = m; j != h; j += (m < h ? 1 : -1))
#define kloop(m, h) for (auto k = m; k != h; k += (m < h ? 1 : -1))
#define lloop(m, h) for (auto l = m; l != h; l += (m < h ? 1 : -1))
#define pll pair<ll, ll>
#define INF 1000000000000000
#define MOD1 1000000007
#define MOD2 998244353
#define MOD3 1000000009
ll n, m, t, t1, t2;
ll a[300005], cans = 0;
vector<ll> c[5], adj[300005];
vector<ll> cd;
ll cr[2][300005];
bool st;
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin >> n >> m >> t;
	iloop(0, n) {
		cin >> a[i];
		a[i]--;
		c[a[i]].push_back(i);
	}
	iloop(0, m) {
		cin >> t1 >> t2;
		t1--, t2--;
		adj[t1].push_back(t2);
		adj[t2].push_back(t1);
	}
	iloop(0, 1<<t) {
		cd.clear();
		jloop(0, t) if (i&(1<<j)) cd.push_back(j);
		if (cd.size() <= 1) continue;
		do {
			st = 1;
			for (auto it : cd) {
				if (st) {
					memset(cr[0], 0, sizeof(cr[0]));
					for (auto it2 : c[it]) cr[0][it2] = 1;
					st = 0;
					continue;
				}
				memset(cr[1], 0, sizeof(cr[1]));
				for (auto it2 : c[it]) for (auto it3 : adj[it2]) cr[1][it2] += cr[0][it3];
				swap(cr[0], cr[1]);
			}
			jloop(0, n) cans += cr[0][j];
		} while (next_permutation(cd.begin(), cd.end()));
	}
	cout << cans;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...