이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
vector <int> adj[maxn];
int n, k , m;
long long ans = 0;
int c[maxn] , cl[6] ,dive = 0;
bool mark[maxn];
void dfs(int v){
if(dive == k)return;
if(mark[v])return;
dive++;
mark[v] = 1;
cl[c[v]]++;
for(int u : adj[v])
dfs(u);
if(cl[1] <= 1 and cl[2] <= 1 and cl[3] <= 1 and cl[4] <= 1 and cl[5] <= 1 and dive > 1)
ans++;
mark[v] = 0;
cl[c[v]]--;
dive--;
}
int main(){
ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
cin >> n >> m >> k;
for(int i = 0; i < n; i++)
cin >> c[i + 1];
for(int i = 0; i < m; i++){
int a, b; cin >> a >> b;
adj[a].push_back(b);
adj[b].push_back(a);
}
for(int i = 0; i < n; i++){
dfs(i + 1);
}
cout << ans << endl;
}
# | 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... |