Submission #870625

#TimeUsernameProblemLanguageResultExecution timeMemory
870625TahirAliyevPaths (BOI18_paths)C++17
23 / 100
3071 ms89684 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define pii pair<int, int> #define oo 1e18 const int MAX = 3e5 + 5; vector<int> g[MAX]; ll dp[33][MAX]; int c[MAX]; int n, m, k; ll rec(int node, int mask){ if(dp[mask][node] != -1) return dp[mask][node]; mask |= (1 << c[node]); ll ans = 0; if(__popcount(mask) >= 2) ans++; for(int to : g[node]){ if(mask & (1 << c[to])){ continue; } ans += rec(to, mask); } return dp[mask][node] = ans; } int main(){ memset(dp, -1, sizeof(dp)); cin >> n >> m >> k; for(int i = 1; i <= n; i++){ cin >> c[i]; c[i]--; } for(int i = 1; i <= m; i++){ int a, b; cin >> a >> b; g[a].push_back(b); g[b].push_back(a); } ll ans = 0; for(int i = 1; i <= n; i++){ ans += rec(i, 0); } cout << ans << '\n'; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...