Submission #514874

#TimeUsernameProblemLanguageResultExecution timeMemory
514874ymmPaths (BOI18_paths)C++17
100 / 100
282 ms56688 KiB
/// /// Oh? You're approaching me? /// #include <bits/stdc++.h> #define Loop(x,l,r) for(ll x = ll(l); x < ll(r); ++x) #define LoopR(x,l,r) for(ll x = ll(r)-1; x >= ll(l); --x) #define Kill(x) exit((cout << (x) << '\n', 0)) typedef long long ll; typedef std::pair<int,int> pii; typedef std::pair<ll,ll> pll; using namespace std; const int N = 300010; vector<int> A[N]; int c[N]; ll dp[32][N]; int n, m, k; int main() { cin.tie(0) -> sync_with_stdio(false); cin >> n >> m >> k; Loop(i,0,n) cin >> c[i], c[i]=1<<(c[i]-1); Loop(i,0,m){ int v, u; cin >> v >> u; --v; --u; A[v].push_back(u); A[u].push_back(v); } Loop(i,0,n) dp[c[i]][i]=1; Loop(msk,1,1<<k){ if(__builtin_popcount(msk)==1) continue; Loop(v,0,n) { if((msk|c[v]) != msk) continue; for(int u : A[v]) dp[msk][v] += dp[msk^c[v]][u]; } } ll ans = 0; Loop(msk,1,1<<k) Loop(i,0,n) ans += dp[msk][i]; cout << ans-n << '\n'; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...