이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define fi first
#define se second
const int mod=998244353, maxn=1e5+5;
int n, m, k, c[maxn], u, v, ans;
vector<int> adj[maxn];
bool vis[maxn];
void dfs(int now, int state, int jml) {
if(!vis[now]&&(((1<<c[now])&state)==0)) {
if(jml==1) {
ans++;
} else {
vis[now]=true;
for(auto nxt:adj[now]) {
dfs(nxt, state|(1<<c[now]), jml-1);
}
}
vis[now]=false;
}
}
int main() {
ios_base::sync_with_stdio(false); cin.tie(NULL);
cin >> n >> m >> k;
for(int i=1; i<=n; i++) cin >> c[i];
while(m--) {
cin >> u >> v;
adj[u].pb(v);
adj[v].pb(u);
}
for(int jml=2; jml<=k; jml++) {
for(int i=1; i<=n; i++) {
dfs(i, 0, jml);
}
}
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... |