Submission #767912

#TimeUsernameProblemLanguageResultExecution timeMemory
767912raysh07Paths (BOI18_paths)C++17
100 / 100
414 ms100488 KiB
#include <bits/stdc++.h> using namespace std; #define int long long #define INF (int)1e18 #define f first #define s second mt19937_64 RNG(chrono::steady_clock::now().time_since_epoch().count()); int n, m, k; const int N = 3e5 + 69; const int K = 5; int dp[N][1 << K]; vector <int> adj[N]; int a[N]; int cnt(int x){ if (x == 0) return 0; return cnt(x/2) + x % 2; } void Solve() { cin >> n >> m >> k; for (int i = 1; i <= n; i++) { cin >> a[i], a[i]--; dp[i][1 << a[i]] = 1; } for (int i = 1; i <= m; i++){ int u, v; cin >> u >> v; adj[u].push_back(v); adj[v].push_back(u); } for (int it = 2; it <= 5; it++){ vector <int> ok; for (int mask = 1; mask < 32; mask++){ if (cnt(mask) == it) ok.push_back(mask); } for (int i = 1; i <= n; i++){ for (int j : adj[i]){ for (auto mask : ok){ if (mask >> a[i] & 1){ dp[i][mask] += dp[j][mask ^ (1 << a[i])]; } } } } } int ans = 0; for (int i = 1; i <= n; i++){ for (int j = 1; j < 32; j++){ ans += dp[i][j]; } } cout << ans - n << "\n"; } int32_t main() { auto begin = std::chrono::high_resolution_clock::now(); ios_base::sync_with_stdio(0); cin.tie(0); int t = 1; // cin >> t; for(int i = 1; i <= t; i++) { //cout << "Case #" << i << ": "; Solve(); } auto end = std::chrono::high_resolution_clock::now(); auto elapsed = std::chrono::duration_cast<std::chrono::nanoseconds>(end - begin); cerr << "Time measured: " << elapsed.count() * 1e-9 << " seconds.\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...