Submission #348989

#TimeUsernameProblemLanguageResultExecution timeMemory
348989bluePaths (BOI18_paths)C++17
0 / 100
10 ms8172 KiB
#include <iostream> #include <vector> using namespace std; int N, M, K; int col[300001]; vector<int> edge[300001]; vector< vector<int> > dp; int curr; int count1[33]; void dfs(int u, int mask) { if(mask & (1 << col[u])) return; mask += (1 << col[u]); dp[curr][mask - (1 << col[curr])] += 1; if(count1[mask] < 3) for(int v: edge[u]) dfs(v, mask); } int main() { cin >> N >> M >> K; for(int i = 1; i <= N; i++) { cin >> col[i]; col[i]--; } int a, b; for(int i = 1; i <= N-1; i++) { cin >> a >> b; edge[a].push_back(b); edge[b].push_back(a); } count1[0] = 0; for(int i = 1; i <= 32; i++) count1[i] = count1[i/2] + (i % 2); dp = vector< vector<int> >(N+1, vector<int>((1 << K), 0)); for(curr = 1; curr <= N; curr++) dfs(curr, 0); // for(int i = 1; i <= N; i++) // { // for(int j = 0; j < (1 << K); j++) cout << dp[i][j] << ' '; // cout << '\n'; // } long long res = 0; for(int i = 1; i <= N; i++) { for(int mask = 0; mask < (1 << K); mask++) { res += dp[i][mask]; } } cout << res - N << '\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...