Submission #385156

#TimeUsernameProblemLanguageResultExecution timeMemory
385156vishesh312Paths (BOI18_paths)C++17
100 / 100
599 ms96748 KiB
#include "bits/stdc++.h" using namespace std; /* #include <ext/pb_ds/assoc_container.hpp> using namespace __gnu_pbds; using ordered_set = tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>; */ #define all(x) begin(x), end(x) #define sz(x) (int)x.size() using ll = long long; const int mod = 1e9+7; vector<vector<int>> adj; vector<vector<ll>> dp; vector<int> c; ll dfs(int u, int mask) { if (dp[mask][u] != -1) return dp[mask][u]; if (mask&(1<<c[u])) return dp[mask][u] = 0; dp[mask][u] = 1; for (int v : adj[u]) { dp[mask][u] += dfs(v, mask|(1<<c[u])); } return dp[mask][u]; } void solve(int tc) { int n, m, k; cin >> n >> m >> k; dp.resize(1<<(k+1)); adj.resize(n), c.resize(n); for (auto &x : dp) x.resize(n, -1); for (auto &x : c) cin >> x; for (int i = 0; i < m; ++i) { int u, v; cin >> u >> v; --u, --v; adj[u].push_back(v); adj[v].push_back(u); } ll ans = 0; for (int i = 0; i < n; ++i) { ans += dfs(i, 0); } cout << ans-n << '\n'; } signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int tc = 1; //cin >> tc; for (int i = 1; i <= tc; ++i) solve(i); 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...