Submission #703045

#TimeUsernameProblemLanguageResultExecution timeMemory
703045Ronin13Paths (BOI18_paths)C++14
100 / 100
357 ms97132 KiB
#include <bits/stdc++.h> #define ll long long #define f first #define s second #define pii pair<int,int> #define pll pair<ll,ll> #define pb push_back #define epb emplace_back using namespace std; const int nmax = 2000001; ll dp[nmax][32]; int main(){ ios_base::sync_with_stdio(false); cin.tie(0); int n, m; cin >> n >> m; int k; cin >> k; int col[n + 1]; for(int i = 1; i <= n; i++){ cin >> col[i]; col[i]--; dp[i][(1 << col[i])] = 1; } vector <vector <int> >g(n + 1); for(int i = 1; i <= m; i++){ int u, v; cin >> u >> v; g[u].pb(v); g[v].pb(u); } for(int mask = 1; mask < (1 << k); mask++){ for(int i = 1; i <= n; i++){ if(mask & (1 << col[i])){ for(int to : g[i]){ dp[i][mask] += dp[to][mask ^ (1 << col[i])]; } } } } ll ans = 0; for(int i = 1; i < 32; i++){ for(int v = 1; v <= n; v++){ ans += dp[v][i]; } } cout << ans - n; 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...