Submission #488101

#TimeUsernameProblemLanguageResultExecution timeMemory
488101MohamedAhmed04Paths (BOI18_paths)C++14
100 / 100
421 ms172328 KiB
#include <bits/stdc++.h> using namespace std ; const int MAX = 3e5 + 10 ; int arr[MAX] ; int n , m , k ; vector< vector<int> >adj(MAX) ; long long dp[MAX][64] ; void dfs(int node , int mask) { if(dp[node][mask]) return ; dp[node][mask] = 1 ; for(auto &child : adj[node]) { if((mask & (1 << arr[child]))) continue ; dfs(child , mask | (1 << arr[child])) ; dp[node][mask] += dp[child][mask | (1 << arr[child])] ; } } int main() { ios_base::sync_with_stdio(0) ; cin.tie(0) ; cin>>n>>m>>k ; for(int i = 1 ; i <= n ; ++i) { cin>>arr[i] ; arr[i]-- ; } for(int i = 0 ; i < m ; ++i) { int x , y ; cin>>x>>y ; adj[x].push_back(y) ; adj[y].push_back(x) ; } long long ans = 0 ; for(int i = 1 ; i <= n ; ++i) { dfs(i , (1 << arr[i])) ; ans += dp[i][(1 << arr[i])] - 1 ; } return cout<<ans<<"\n" , 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...