Submission #473510

#TimeUsernameProblemLanguageResultExecution timeMemory
473510ZaZo_Paths (BOI18_paths)C++14
100 / 100
468 ms100068 KiB
#include <bits/stdc++.h> #define ZAZO ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); #define int long long using namespace std; int n , m , k; vector<int>edges[300001]; int cols[300001]; int DP[300001][1<<5]; int DO_WORK(int node , int mask) { if(DP[node][mask]!=-1) return DP[node][mask]; int mask2 = mask | (1<<(cols[node])); DP[node][mask]=1; for(auto newnode : edges[node]) { if(!((1<<cols[newnode])&mask2)) { DP[node][mask] += DO_WORK(newnode , mask2); } } return DP[node][mask]; } int32_t main() { ZAZO memset(DP,-1,sizeof DP); cin >> n >> m >> k ; for(int i = 1 ; i <= n ; i++) cin>>cols[i],cols[i]--; for(int i = 0 ; i < m ; i++) { int u , v; cin >> u >> v; edges[u].push_back(v); edges[v].push_back(u); } int ans=0; for(int i = 1 ; i <= n ; i++) { ans+=DO_WORK(i,0); } 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...