제출 #721997

#제출 시각아이디문제언어결과실행 시간메모리
721997Jarif_RahmanPaths (BOI18_paths)C++17
100 / 100
386 ms70636 KiB
#include <bits/stdc++.h>
#define pb push_back
#define f first
#define sc second
using namespace std;
typedef long long int ll;
typedef string str;
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    int n, m, k; cin >> n >> m >> k;
    vector<int> color(n);
    for(int &x: color) cin >> x, x--;
    vector<vector<int>> graph(n);
    for(int i = 0; i < m; i++){
        int a, b; cin >> a >> b; a--, b--;
        graph[a].pb(b);
        graph[b].pb(a);
    }

    vector<vector<ll>> dp(n, vector<ll>((1<<k), 0));
    for(int i = 0; i < n; i++) dp[i][1<<color[i]] = 1;

    for(int i = 0; i < (1<<k); i++){
        if(__builtin_popcount(i) < 2) continue;
        for(int j = 0; j < n; j++) if(i&(1<<color[j])){
            for(int x: graph[j]) dp[j][i]+=dp[x][i^(1<<color[j])];
        }
    }

    ll ans = 0;
    for(int i = 0; i < (1<<k); i++) if(__builtin_popcount(i) > 1)
        for(int j = 0; j < n; j++) ans+=dp[j][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...