제출 #307842

#제출 시각아이디문제언어결과실행 시간메모리
3078422fat2codePaths (BOI18_paths)C++17
100 / 100
752 ms173048 KiB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define all(a) (a).begin(), (a).end()
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#define fr first
#define sc second
#define int long long
#define mp make_pair
#define rc(s) return cout<<s,0
#define rcc(s) cout<<s,exit(0)

const int nmax = 300005;
const int mask = (1 << 5);

int n,m,k,dp[nmax][mask],tz[nmax][mask],color[nmax],ans;
vector<int>nod[nmax];

int32_t main(){
    ios_base::sync_with_stdio(false);cin.tie(0);cerr.tie(0);cout.tie(0);
    srand(chrono::steady_clock::now().time_since_epoch().count());
 //   freopen("input.in","r",stdin);
    cin >> n >> m >> k;
    for(int i=1;i<=n;i++){
        cin >> color[i];
        dp[i][1 << (color[i] - 1)] = 1;
    }
    for(int i=1;i<=m;i++){
        int x,y;
        cin >> x >> y;
        nod[x].push_back(y);
        nod[y].push_back(x);
    }
    for(int i=2;i<=k;i++){
        for(int j=1;j<=n;j++){
            for(int t=1;t<(1 << k);t++){
                tz[j][t] = dp[j][t];
                dp[j][t] = 0;
            }
        }
        for(int j=1;j<=n;j++){
            for(auto it : nod[j]){
                for(int t=1;t<(1<<k);t++){
                    if((t&(1<<(color[j] - 1))) == 0){
                        dp[j][t^(1<<(color[j]-1))] += tz[it][t];
                    }
                }
            }
        }
        for(int j=1;j<=n;j++){
            for(int t=1;t<(1<<k);t++){
                ans += dp[j][t];
            }
        }
    }
    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...