Submission #473659

#TimeUsernameProblemLanguageResultExecution timeMemory
473659Sarah_MokhtarPaths (BOI18_paths)C++14
100 / 100
911 ms472912 KiB
#include<bits/stdc++.h> using namespace std; typedef long long ll; #define read freopen("acpc.in","r",stdin); #define LESSGO ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); const ll N=3e5+10,M=505,OO=1e16,mod=1e9+9; int n,m,k,col[N]; vector<int>adj[N]; ll dp[N][1<<6][3]; ll solve(int src,int msk,int cnt){ ll& ret=dp[src][msk][cnt]; if(~ret) return ret; ret=(cnt==2); for(int i:adj[src]){ if(msk&(1ll<<col[i])) continue; ret+=solve(i,msk|(1ll<<col[i]),cnt+(cnt==1)); } return ret; } int main(){ memset(dp,-1,sizeof dp); cin>>n>>m>>k; for(int i=0;i<n;++i) cin>>col[i]; while(m--){ int u,v; cin>>u>>v; --u,--v; adj[u].push_back(v); adj[v].push_back(u); } ll ans=0; for(int i=0;i<n;++i){ ans+=solve(i,1<<col[i],1); } 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...