Submission #522511

#TimeUsernameProblemLanguageResultExecution timeMemory
522511Leonardo_PaesPaths (BOI18_paths)C++17
70 / 100
328 ms58128 KiB
#include <bits/stdc++.h>
using namespace std;

const int maxn = 3e5+10, maxl = 1<<5 - 1;

int c[maxn];
vector<int> grafo[maxn];

long long dp[maxn][maxl];

long long solve(int u, int mask){
	if(dp[u][mask] != -1) return dp[u][mask];
	long long tot = 1;
	for(int v : grafo[u]) if(!(mask&c[v])) tot += solve(v, mask^c[v]);
	return dp[u][mask] = tot;
}

int main(){
	ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
	int n, m, k;
	cin >> n >> m >> k;
	for(int i=1; i<=n; i++){
		cin >> c[i];
		c[i] = (1<<(c[i]-1));
	}
	for(int i=1; i<=m; i++){
		int u, v;
		cin >> u >> v;
		grafo[u].push_back(v);
		grafo[v].push_back(u);
	}
	long long ans = 0;
	memset(dp, -1, sizeof dp);
	for(int i=1; i<=n; i++) ans += solve(i, c[i]);
	cout << ans - n << "\n";
	return 0;
}

Compilation message (stderr)

paths.cpp:4:38: warning: suggest parentheses around '-' inside '<<' [-Wparentheses]
    4 | const int maxn = 3e5+10, maxl = 1<<5 - 1;
      |                                    ~~^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...