이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define rep(n) for (int i = 0; i < n; ++i)
#define rep2(n) for (int j = 0; j < n; ++j)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef pair<double, double> dd;
const int mxn = 5e5+5, mxa = 32;
ll dp[mxn][mxa], col[mxn];
vi neibs[mxn];
ll f (int c, int C) {
if (dp[c][C]!=-1) return dp[c][C];
ll res = C!=0, cur = C|(1<<col[c]);
for (int v : neibs[c]) if (((1<<col[v])&cur)==0) res += f (v, cur);
dp[c][C] = res;
return res;
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
memset(dp, -1, mxn*mxa*sizeof(ll));
int n, m, k, a, b;
cin >> n >> m >> k;
rep (n) {
cin >> col[i];
col[i]--;
}
rep (m) {
cin >> a >> b;
neibs[a-1].pb(b-1);
neibs[b-1].pb(a-1);
}
ll ans = 0;
rep (n) ans += f(i, 0);
cout << ans << "\n";
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... |