Archives
Trending
Support
Login
clear text
XML
Django
JavaScript
MATLAB
C
C++
C#
Python
SQL
Shell
Bash
Markdown
YAML
JSON
HTML
CSS
PHP
Java
Ruby
Go
Rust
Swift
Kotlin
Arduino
TypeScript
Perl
Autohotkey
Lua
SQF
R
Scala
Haskell
Groovy
Dart
Clojure
VB.NET
Objective-C
PowerShell
Bash
CoffeeScript
Verilog
#include
#include
#include
#include
using namespace std; typedef long long ll; const int maxn = 3e5 + 10; vector
graph[maxn]; ll dp[maxn][1 << 5]; int color[maxn]; ll dfs(int node, int bitmask, int length) { if(dp[node][bitmask] != -1) { return dp[node][bitmask]; } ll res = 0; if(dp[node][bitmask] != -1) { return dp[node][bitmask]; } if(length >= 2) { res++; } for(int neighbour : graph[node]) { if(!(bitmask & (1 << color[neighbour]))) { res += dfs(neighbour, bitmask | (1 << color[neighbour]), length + 1); } } return dp[node][bitmask] = res; } int main(int argc, const char * argv[]) { int n, m, k; cin >> n >> m >> k; for(int i = 0; i < n; i++) { cin >> color[i]; color[i]--; } for(int i = 0; i < m; i++) { int a, b; cin >> a >> b; a--; b--; graph[a].push_back(b); graph[b].push_back(a); } memset(dp, -1, sizeof dp); ll res = 0; for(int i = 0; i < n; i++) { res += dfs(i, (1 << color[i]), 1); } cout << res << endl; return 0; } //4 3 3 1 2 1 3 1 2 //2 3 //4 2
Mark as private (unlisted)
for 30 minutes
for 6 hours
for 1 day
for 1 week
for 1 month
for 1 year
everlasting (like CCCP)