#include <bits/stdc++.h>
#define int long long
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
const int N = 3e5+5;
vector<int> adj[N];
int col[N], visited[6];
int ans = 0;
void dfs(int u){
visited[col[u]] = 1;
ans++;
for(auto v : adj[u]){
if(visited[col[v]]) continue;
int tmp = visited[col[v]];
visited[col[v]] = 1;
dfs(v);
visited[col[v]] = tmp;
}
}
signed main(){
fastio
int n,m,k;
cin >> n >> m >> k;
for(int i = 1;i <= n;i++){
cin >> col[i];
}
for(int i = 0;i < m;i++){
int u,v;
cin >> u >> v;
adj[u].push_back(v);
adj[v].push_back(u);
}
for(int i = 1;i <= n;i++){
visited[col[i]] = 1;
dfs(i);
visited[col[i]] = 0;
}
cout << ans-n << "\n";
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
7244 KB |
Output is correct |
2 |
Correct |
5 ms |
7244 KB |
Output is correct |
3 |
Correct |
5 ms |
7368 KB |
Output is correct |
4 |
Correct |
5 ms |
7244 KB |
Output is correct |
5 |
Correct |
5 ms |
7244 KB |
Output is correct |
6 |
Correct |
5 ms |
7364 KB |
Output is correct |
7 |
Correct |
5 ms |
7244 KB |
Output is correct |
8 |
Correct |
5 ms |
7244 KB |
Output is correct |
9 |
Correct |
5 ms |
7244 KB |
Output is correct |
10 |
Correct |
5 ms |
7364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3055 ms |
14624 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
7244 KB |
Output is correct |
2 |
Correct |
5 ms |
7244 KB |
Output is correct |
3 |
Correct |
5 ms |
7368 KB |
Output is correct |
4 |
Correct |
5 ms |
7244 KB |
Output is correct |
5 |
Correct |
5 ms |
7244 KB |
Output is correct |
6 |
Correct |
5 ms |
7364 KB |
Output is correct |
7 |
Correct |
5 ms |
7244 KB |
Output is correct |
8 |
Correct |
5 ms |
7244 KB |
Output is correct |
9 |
Correct |
5 ms |
7244 KB |
Output is correct |
10 |
Correct |
5 ms |
7364 KB |
Output is correct |
11 |
Execution timed out |
3055 ms |
14624 KB |
Time limit exceeded |
12 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
7244 KB |
Output is correct |
2 |
Execution timed out |
3093 ms |
9920 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |