Submission #579763

#TimeUsernameProblemLanguageResultExecution timeMemory
579763HeyYouNotYouYouPaths (BOI18_paths)C++14
100 / 100
585 ms112056 KiB
#include <bits/stdc++.h> #define int long long #define endl '\n' using namespace std; const int N = 300001,INF=1e12; int n , m , k , x , vis[N] , col[N] , ans; int dp[N][(1<<5)+5]; vector<int>edges[N]; int dfs(int node , int mask){ if(dp[node][mask]!=-1){ return dp[node][mask]; } dp[node][mask]=1; for(auto e:edges[node]){ if(!((1<<col[e])&mask)){ dp[node][mask]+=dfs(e , mask|(1<<col[e])); } } return dp[node][mask]; } int32_t main() { //freopen("abc.in", "r", stdin); memset(dp,-1,sizeof dp); cin >> n >> m >> k ; for(int i = 1 ; i <= n ; i ++){ cin >> x; col[i]=x; } for(int i = 0 ; i < m ; i ++) { int u , v ; cin >> u >> v; edges[u].push_back(v); edges[v].push_back(u); } for(int i = 1 ; i <= n ; i++) { ans+=dfs(i,1<<col[i]); } cout<<ans-n<<endl; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...