#include<bits/stdc++.h>
using namespace std;
const int N = (int)3e5+3;
const int MOD = (int)1e6+3;
int n, m, k, a[N];
vector<int> g[N];
bool used[N];
int ans = 0;
void dfs(int v) {
used[a[v]] = 1;
ans++;
for(auto to : g[v]) {
if(!used[a[to]]) {
dfs(to);
}
}
used[a[v]] = 0;
}
int main() {
ios_base::sync_with_stdio(NULL);
cin.tie(0);
cin >> n >> m >> k;
for(int i = 1; i <= n; ++i) {
cin >> a[i];
}
for(int i = 1; i <= m; ++i) {
int u, v;
cin >> u >> v;
if(a[u] == a[v]) {
continue;
}
g[u].push_back(v);
g[v].push_back(u);
}
for(int i = 1; i <= n; ++i) {
dfs(i);
}
cout << ans-n;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
8536 KB |
Output is correct |
2 |
Correct |
2 ms |
8640 KB |
Output is correct |
3 |
Correct |
2 ms |
8536 KB |
Output is correct |
4 |
Correct |
2 ms |
8540 KB |
Output is correct |
5 |
Correct |
2 ms |
8536 KB |
Output is correct |
6 |
Correct |
2 ms |
8632 KB |
Output is correct |
7 |
Correct |
1 ms |
8540 KB |
Output is correct |
8 |
Correct |
2 ms |
8540 KB |
Output is correct |
9 |
Correct |
2 ms |
8540 KB |
Output is correct |
10 |
Correct |
2 ms |
8540 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1501 ms |
11580 KB |
Output is correct |
2 |
Execution timed out |
3069 ms |
10580 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
8536 KB |
Output is correct |
2 |
Correct |
2 ms |
8640 KB |
Output is correct |
3 |
Correct |
2 ms |
8536 KB |
Output is correct |
4 |
Correct |
2 ms |
8540 KB |
Output is correct |
5 |
Correct |
2 ms |
8536 KB |
Output is correct |
6 |
Correct |
2 ms |
8632 KB |
Output is correct |
7 |
Correct |
1 ms |
8540 KB |
Output is correct |
8 |
Correct |
2 ms |
8540 KB |
Output is correct |
9 |
Correct |
2 ms |
8540 KB |
Output is correct |
10 |
Correct |
2 ms |
8540 KB |
Output is correct |
11 |
Correct |
1501 ms |
11580 KB |
Output is correct |
12 |
Execution timed out |
3069 ms |
10580 KB |
Time limit exceeded |
13 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
8540 KB |
Output is correct |
2 |
Execution timed out |
3079 ms |
9564 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |