#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize ("unroll-loops,Ofast,O3")
#pragma GCC target("avx,avx2,fma")
#define F first
#define S second
#define sz(x) (int)x.size()
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define NFS ios_base::sync_with_stdio(0) , cin.tie(0) , cout.tie(0) ;
#define file(s) if (fopen(s".in", "r")) freopen(s".in", "r", stdin), freopen(s".out", "w", stdout)
typedef long long ll;
const int E = 1e6+777;
const long long inf = 1e18+777;
const int N = 1e5+324;
const int MOD = 1e9+7;
int n, m, k, c[N];
vector<int> g[N];
vector <bool> color(6), used(N);
int sum;
void dfs(int v, int h){
used[v] = true;
color[c[v]] = true;
if(h > 1){
// cerr << "v: " << v << '\n';
++sum;
// return;
}
// cerr << "to("<<v<<")\n";
// for(auto to : g[v]){
// if(!color[c[to]] && !used[to]){
// cerr << to << " ";
// }
// }
// cerr << "\n";
for(auto it : g[v]){
if(!color[c[it]] && !used[it]){
dfs(it, h + 1);
}
}
color[c[v]] = false;
used[v] = false;
}
int main(){
cin >> n >> m >> k;
for(int i = 1; i <= n; ++i){
cin >> c[i];
}
for(int i = 1; i <= m; ++i){
int x, y;
cin >> x >> y;
g[x].pb(y);
g[y].pb(x);
}
for(int i = 1; i <= n; ++i){
dfs(i, 1);
}
cout << sum << '\n';
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2636 KB |
Output is correct |
2 |
Correct |
2 ms |
2636 KB |
Output is correct |
3 |
Correct |
1 ms |
2636 KB |
Output is correct |
4 |
Correct |
2 ms |
2636 KB |
Output is correct |
5 |
Correct |
2 ms |
2636 KB |
Output is correct |
6 |
Correct |
2 ms |
2636 KB |
Output is correct |
7 |
Correct |
2 ms |
2636 KB |
Output is correct |
8 |
Correct |
1 ms |
2636 KB |
Output is correct |
9 |
Correct |
3 ms |
2636 KB |
Output is correct |
10 |
Correct |
2 ms |
2636 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3004 ms |
8976 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2636 KB |
Output is correct |
2 |
Correct |
2 ms |
2636 KB |
Output is correct |
3 |
Correct |
1 ms |
2636 KB |
Output is correct |
4 |
Correct |
2 ms |
2636 KB |
Output is correct |
5 |
Correct |
2 ms |
2636 KB |
Output is correct |
6 |
Correct |
2 ms |
2636 KB |
Output is correct |
7 |
Correct |
2 ms |
2636 KB |
Output is correct |
8 |
Correct |
1 ms |
2636 KB |
Output is correct |
9 |
Correct |
3 ms |
2636 KB |
Output is correct |
10 |
Correct |
2 ms |
2636 KB |
Output is correct |
11 |
Execution timed out |
3004 ms |
8976 KB |
Time limit exceeded |
12 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2636 KB |
Output is correct |
2 |
Execution timed out |
3069 ms |
4436 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |