Submission #490602

#TimeUsernameProblemLanguageResultExecution timeMemory
490602radalPaths (BOI18_paths)C++14
100 / 100
348 ms115948 KiB
#include <bits/stdc++.h> #pragma GCC optimize("O3,no-stack-protector,unroll-loops") #pragma GCC target("avx2,fma") #define rep(i,l,r) for (int i = l; i < r; i++) #define repr(i,r,l) for (int i = r; i >= l; i--) #define X first #define Y second #define pb push_back #define endl '\n' #define debug(x) cerr << #x << " : " << x << endl; using namespace std; typedef long long ll; typedef long double ld; typedef pair<int,int> pll; typedef pair<long double,long double> pld; const long long int N = 3e5+10,mod = 1e9+7,inf = 1e9,sq = 700,sig = 26; inline int mkay(int a,int b){ if (a+b >= mod) return a+b-mod; if (a+b < 0) return a+b+mod; return a+b; } inline int poww(int n,int k){ int c = 1; while (k){ if (k&1) c = (1ll*c*n)%mod; n = (1ll*n*n)%mod; k >>= 1; } return c; } ll dp[N][40]; vector<int> adj[N]; int c[N]; int main(){ ios :: sync_with_stdio(0); cin.tie(0);cout.tie(0); int n,m,k; cin >> n >> m >> k; rep(i,1,n+1){ cin >> c[i]; c[i]--; } rep(i,0,m){ int u,v; cin >> v >> u; adj[u].pb(v); adj[v].pb(u); } int y = (1 << k); rep(i,1,n+1) dp[i][(1 << c[i])] = 1; ll ans = 0; rep(j,1,y){ rep(i,1,n+1){ if ((j&(1 << c[i])) == 0) continue; int x = j-(1<< c[i]); if (!x) continue; for (int u : adj[i]) dp[i][j] += dp[u][x]; ans += dp[i][j]; } } cout << ans; 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...