이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define fi first
#define si second
typedef pair<int,int> pi;
typedef tuple<int,int,int> ti;
template<typename T> bool chmin(T &a, T b){return (b < a) ? a = b, 1 : 0;}
template<typename T> bool chmax(T &a, T b){return (b > a) ? a = b, 1 : 0;}
void debug_out() {cerr<<endl;}
template <typename Head, typename... Tail>
void debug_out(Head _H, Tail... _T) {cerr<<" "<<to_string(_H);debug_out(_T...);}
#define debug(...) cerr<<"["<<#__VA_ARGS__<<"]:",debug_out(__VA_ARGS__)
const int N = 300010;
int n,m,k;
int c[N];
vector<int> g[N];
ll dp[40][N], ans;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
cin.exceptions(ios::badbit|ios::failbit);
cin>>n>>m>>k;
for (int i = 1; i <= n; ++i) {
cin >> c[i];
--c[i];
}
for (int i = 1; i <= m; ++i) {
int u,v; cin >>u>>v;
g[u].push_back(v);
g[v].push_back(u);
}
for (int i = 1; i <= n; ++i) dp[(1<<c[i])][i]=1;
for (int i = 1; i < (1<<k); ++i) {
for (int j = 1; j <= n; ++j) {
if (!(i&(1<<c[j]))) continue;
int p = i^(1<<c[j]);
for (auto v: g[j]) {
dp[i][j] += dp[p][v];
}
}
}
for (int i = 1; i < (1<<k); ++i) {
if (__builtin_popcount(i)==1) continue;
for (int j = 1; j <= n; ++j) ans += dp[i][j];
}
cout << ans;
return 0;
}
# | 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... |