Submission #518395

#TimeUsernameProblemLanguageResultExecution timeMemory
518395IerusPaths (BOI18_paths)C++14
100 / 100
458 ms317484 KiB
#include<bits/stdc++.h> using namespace std; #pragma GCC optimize ("unroll-loops,Ofast,O3") #pragma GCC target("avx,avx2,fma") #define F first #define S second #define sz(x) (int)x.size() #define pb push_back #define eb emplace_back #define rall(x) (x).rbegin(),(x).rend() #define NFS ios_base::sync_with_stdio(0) , cin.tie(0) , cout.tie(0) ; #define file(s) if (fopen(s".in", "r")) freopen(s".in", "r", stdin), freopen(s".out", "w", stdout) typedef long long ll; const int E = 1e6+777; const long long inf = 1e18+777; const int N = 3e5+324; const int MOD = 1e9+7; long long res; int n, m, k, c[N]; vector<int> g[N]; long long cnt[6][N][(1<<5)]; void Count(int v, int x){ for(auto to : g[v]){ if(c[to] == c[v]) continue; for(int mask = 0; mask < (1 << k); ++mask){ if(((mask >> c[v]) & 1)) continue; cnt[x][v][mask|(1<<c[v])] += cnt[x-1][to][mask]; }; }; } int main(){ ios_base::sync_with_stdio(0) , cin.tie(0) , cout.tie(0) ; cin >> n >> m >> k; for(int i = 1; i <= n; ++i){ cin >> c[i]; --c[i]; cnt[1][i][(1<<c[i])] = 1; } for(int i = 1; i <= m; ++i){ int x, y; cin >> x >> y; g[x].pb(y); g[y].pb(x); } for(int x = 2; x <= k; ++x){ for(int i = 1; i <= n; ++i){ Count(i, x); } } long long sum = 0; for(int x = 2; x <= k; ++x){ for(int i = 1; i <= n; ++i){ for(int j = 0; j < (1 << k); ++j){ sum += cnt[x][i][j]; } } } cout << sum; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...