Submission #524641

#TimeUsernameProblemLanguageResultExecution timeMemory
524641Yazan_AlattarPaths (BOI18_paths)C++14
100 / 100
953 ms180512 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define F first #define S second #define pb push_back #define endl "\n" #define all(x) x.begin(), x.end() const int M = 2000007; const ll inf = 1e18; const ll mod = 998244353; const double pi = acos(-1); const int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1}; vector <int> adj[M]; ll n, m, k, col[M], dp[M][50], ans; int main() { cin >> n >> m >> k; for(int i = 1; i <= n; ++i) cin >> col[i], --col[i]; for(int i = 1; i <= m; ++i){ int a, b; cin >> a >> b; adj[a].pb(b); adj[b].pb(a); } for(int i = 1; i <= n; ++i) dp[i][(1 << col[i])] = 1; for(int mask = 1; mask < (1 << k); ++mask){ for(int i = 1; i <= n; ++i){ for(auto j : adj[i]) if(((mask >> col[j]) & 1) == 0){ dp[j][(mask | (1 << col[j]))] += dp[i][mask]; } ans += dp[i][mask]; } } cout << ans - n << endl; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...