이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |