Submission #667044

#TimeUsernameProblemLanguageResultExecution timeMemory
667044Darren0724Paths (BOI18_paths)C++17
100 / 100
401 ms64696 KiB
#include<bits/stdc++.h> using namespace std; #define int long long #define all(x) x.begin(),x.end() int INF=1e18; signed main(){ ios_base::sync_with_stdio(false); cin.tie(0); int n,m,k;cin>>n>>m>>k; vector<int> c(n); for(int i=0;i<n;i++){ cin>>c[i]; c[i]--; } vector<vector<int>> adj(n); for(int i=0;i<m;i++){ int a,b;cin>>a>>b;a--;b--; adj[a].push_back(b); adj[b].push_back(a); } vector<vector<int>> dp((1<<k),vector<int>(n)); for(int i=0;i<n;i++){ dp[(1<<c[i])][i]=1; } for(int i=1;i<(1<<k);i++){ for(int j=0;j<n;j++){ if(i&(1<<c[j])){ for(int e:adj[j]){ dp[i][j]+=dp[i^(1<<c[j])][e]; } } } } int ans=0; for(int i=0;i<(1<<k);i++){ for(int j=0;j<n;j++){ ans+=dp[i][j]; } } cout<<ans-n<<endl; 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...