Submission #106151

#TimeUsernameProblemLanguageResultExecution timeMemory
106151xiaowuc1Paths (BOI18_paths)C++14
100 / 100
579 ms97272 KiB
#include <algorithm> #include <cassert> #include <cstring> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <random> #include <set> #include <vector> using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, int> plli; typedef vector<vector<ll>> matrix; int n, m, k; vector<int> edges[300005]; int colors[300005]; ll dp[300005][32]; void solve() { cin >> n >> m >> k; for(int i = 0; i < n; i++) { cin >> colors[i]; colors[i]--; } while(m--) { int a, b; cin >> a >> b; edges[--a].push_back(--b); edges[b].push_back(a); } for(int i = 0; i < n; i++) { for(int out: edges[i]) { if(colors[i] != colors[out]) { dp[out][(1 << colors[i]) | (1 << colors[out])]++; } } } ll ret = 0; for(int mask = 1; mask < (1<<k); mask++) { for(int i = 0; i < n; i++) { if(dp[i][mask] == 0) continue; ret += dp[i][mask]; for(int out: edges[i]) { if(mask&(1<<colors[out])) continue; dp[out][mask | (1 << colors[out])] += dp[i][mask]; } } } cout << ret << "\n"; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); /* int t; cin >> t; for(int i = 1; i <= t; i++) { cout << "Case #" << i << ": "; solve(); } */ solve(); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...