Submission #473382

#TimeUsernameProblemLanguageResultExecution timeMemory
473382fadi57Paths (BOI18_paths)C++14
53 / 100
214 ms56700 KiB
#include<bits/stdc++.h> using namespace std; const int mx=1e5+10; typedef long long ll; int mod=1e9+7; const int MXm=22; #define F first #define S second const int inf=1e9+10; ll dp[mx][1<<5]; int c[mx]; vector<int>adj[mx]; int n,m,k; ll solve(int node,int mask){ ll &ret=dp[node][mask]; if(ret!=-1){ return ret; } ret=1; for(auto it:adj[node]){ if(!((1<<c[it])&mask)){ ret+=solve(it,mask|(1<<c[it])); } } return ret; } int main(){ memset(dp,-1,sizeof(dp)); cin>>n>>m>>k; for(int i=1;i<=n;i++){ cin>>c[i]; c[i]--; } ll ans=0; for(int i=1;i<=m;i++){ int a,b;cin>>a>>b; adj[a].push_back(b); adj[b].push_back(a); } for(int i=1;i<=n;i++){ ans+=solve(i,1<<c[i]); } cout<<ans-n; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...