제출 #331065

#제출 시각아이디문제언어결과실행 시간메모리
331065nandonathanielPaths (BOI18_paths)C++14
100 / 100
535 ms97388 KiB
#include<bits/stdc++.h> using namespace std; const int MAXN=300005,LOG=5; long long dp[MAXN][1<<LOG]; vector<int> adj[MAXN]; int c[MAXN]; long long DP(int now,int mask){ long long &ret=dp[now][mask]; if(ret!=-1)return ret; ret=1; for(auto nxt : adj[now]){ if(mask & (1<<c[nxt]))continue; ret+=DP(nxt,mask+(1<<c[nxt])); } return ret; } int main(){ ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); int n,m,k,u,v; cin >> n >> m >> k; for(int i=1;i<=n;i++){ cin >> c[i]; c[i]--; } for(int i=1;i<=m;i++){ cin >> u >> v; adj[u].push_back(v); adj[v].push_back(u); } memset(dp,-1,sizeof(dp)); long long ans=-n; for(int i=1;i<=n;i++){ ans+=DP(i,1<<c[i]); } cout << ans << '\n'; 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...