Submission #975159

#TimeUsernameProblemLanguageResultExecution timeMemory
975159LOLOLOPaths (BOI18_paths)C++14
100 / 100
347 ms97184 KiB
#include <bits/stdc++.h> #define ll long long using namespace std; #define f first #define s second #define pb push_back #define ep emplace #define eb emplace_back #define lb lower_bound #define ub upper_bound #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() #define uniquev(v) sort(all(v)), (v).resize(unique(all(v)) - (v).begin()) #define mem(f,x) memset(f , x , sizeof(f)) #define sz(x) (int)(x).size() #define __lcm(a, b) (1ll * ((a) / __gcd((a), (b))) * (b)) #define mxx *max_element #define mnn *min_element #define cntbit(x) __builtin_popcountll(x) #define len(x) (int)(x.length()) const int N = 3e5 + 100; ll dp[N][(1 << 5)]; int a[N]; vector <int> ed[N]; ll dfs(int u, int mask) { if (mask == 0) return 1; if (dp[u][mask] != -1) return dp[u][mask]; ll ans = 0; for (auto x : ed[u]) { if ((a[x] & mask) == a[x]) { ans += dfs(x, mask ^ a[x]); } } return dp[u][mask] = ans; } ll solve() { int n, m, k; cin >> n >> m >> k; for (int i = 1; i <= n; i++) { cin >> a[i]; a[i]--; a[i] = (1 << a[i]); } for (int i = 0; i < m; i++) { int a, b; cin >> a >> b; ed[a].pb(b); ed[b].pb(a); } ll ans = 0; for (int i = 1; i <= n; i++) { for (int mask = 1; mask < (1 << k); mask++) { if ((a[i] & mask) == a[i] && cntbit(mask) > 1) { ans += dfs(i, mask ^ a[i]); } } } return ans; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); mem(dp, -1) ; int t = 1; //cin >> t; while (t--) { cout << solve() << '\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...