Submission #782537

#TimeUsernameProblemLanguageResultExecution timeMemory
782537CookiePaths (BOI18_paths)C++14
100 / 100
302 ms98496 KiB
#include<bits/stdc++.h> #include<fstream> using namespace std; ifstream fin("VNOICUP.INP"); ofstream fout("VNOICUP.OUT"); #define sz(a) (int)a.size() #define ll long long #define pb push_back #define forr(i, a, b) for(int i = a; i < b; i++) #define dorr(i, a, b) for(int i = a; i >= b; i--) #define ld long double #define vt vector #include<fstream> #define fi first #define se second #define pll pair<ll, ll> #define pii pair<int, int> const ld PI = 3.14159265359; using u128 = __uint128_t; //const int x[4] = {1, -1, 0, 0}; //const int y[4] = {0, 0, 1, -1}; const ll mod = 1000001; const int mxn = 3e5 + 1, mxq = 2e5 + 5, sq = 400, mxv = 2e7 + 5, p = 31; //const int base = (1 << 18); const ll inf = 1e9 + 5, neg = -69420; ll dp[mxn + 1][(1 << 5)], c[mxn + 1]; int n, m, k; vt<int>adj[mxn + 1]; void input(){ cin >> n >> m >> k; for(int i = 1; i <= n; i++){ cin >> c[i]; c[i]--; dp[i][(1 << c[i])] = 1; } forr(i, 0, m){ int u, v; cin >> u >> v; adj[u].pb(v); adj[v].pb(u); } } void process(){ ll ans = 0; for(int i = 1; i < (1 << k); i++){ for(int j = 1; j <= n; j++){ if((i >> c[j]) & 1){ for(auto l: adj[j]){ dp[j][i] += dp[l][i ^ (1 << c[j])]; } } ans += dp[j][i]; } } cout << ans - n; } signed main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); input(); process(); 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...