Submission #448608

#TimeUsernameProblemLanguageResultExecution timeMemory
448608Killer2501Paths (BOI18_paths)C++14
53 / 100
161 ms72904 KiB
#include<bits/stdc++.h> #define pll pair<ll, ll> #define fi first #define se second #define pb push_back #define pii pair<ll, pll> using namespace std; using ll = long long; const int N = 2e5+55; const ll mod = 1e9+7; const ll mod1 = 1e9+1; const ll base = 311; const ll base1 = 331; ll m, n, t, k, a[N], tong, b[N], dp[N][33], c[N], lab[N], cnt, ans, h[N], d[N]; priority_queue< pll, vector<pll>, greater<pll> > pq; string s[N]; vector<ll> adj[N]; vector<pll> e; ll pw(ll k, ll n) { ll total = 1; for(; n; n >>= 1) { if(n & 1)total = total * k % mod; k = k * k % mod; } return total; } ll cal(ll u, ll mask) { if(dp[u][mask] != -1)return dp[u][mask]; ll total = 1; for(ll v : adj[u]) { if((mask >> a[v]) & 1)continue; total += cal(v, mask | (1<<a[v])); } return dp[u][mask] = total; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> m >> k; for(int i = 1; i <= n; i ++) { cin >> a[i]; --a[i]; } while(m -- > 0) { ll x, y; cin >> x >> y; adj[x].pb(y); adj[y].pb(x); } memset(dp, -1, sizeof(dp)); for(int i = 1; i <= n; i ++) { ans += cal(i, (1<<a[i])); } cout << ans-n; } /* 1 5 9 1 2 3 2 1 3 2 -2 2 2 3 1 3 2 -3 2 2 3 1 1 4 7 1 4 5 8 2 5 2 2 5 1 1 5 6 1 1 2 2 1 2 4 3 2 1 4 1 1 5 6 1 2 3 -2 2 3 5 */
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...