#include <bits/stdc++.h>
using namespace std;
#define ll long long
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define usecppio ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define all(x) ((x).begin()),((x).end())
using pii = pair <int, int>;
#define int ll
#define INF 0x7f7f7f7f7f7f7f7f
const bool debug = false;
int n, m, k;
int memo[303030][32];
vector <int> G[303030];
int color[303030];
int dfs(int r, int use)
{
if (memo[r][use]!=-1)
return memo[r][use];
if (use & (1<<color[r]))
return memo[r][use] = 0;
use |= (1<<color[r]);
int res = 1;
for (auto it:G[r])
{
if (!(use & (1<<color[it])))
{
res += dfs(it, use);
}
else
{
memo[it][use] = 0;
}
}
memo[r][use] = res;
return memo[r][use];
}
int32_t main()
{
usecppio
memset(memo,-1,sizeof(memo));
cin >> n >> m >> k;
for (int i = 1; i<=n; i++) cin >> color[i];
for (int i = 0; i<m; i++)
{
int u, v; cin >> u >> v;
G[u].push_back(v);
G[v].push_back(u);
}
int ans = 0;
for (int i = 1; i<=n; i++)
ans += dfs(i, 0);
cout << ans-n<< '\n';
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
48 ms |
83320 KB |
Output is correct |
2 |
Correct |
46 ms |
83320 KB |
Output is correct |
3 |
Correct |
47 ms |
83448 KB |
Output is correct |
4 |
Correct |
46 ms |
83320 KB |
Output is correct |
5 |
Correct |
47 ms |
83320 KB |
Output is correct |
6 |
Correct |
47 ms |
83420 KB |
Output is correct |
7 |
Correct |
47 ms |
83320 KB |
Output is correct |
8 |
Correct |
46 ms |
83320 KB |
Output is correct |
9 |
Correct |
48 ms |
83320 KB |
Output is correct |
10 |
Correct |
46 ms |
83320 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3094 ms |
90488 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
48 ms |
83320 KB |
Output is correct |
2 |
Correct |
46 ms |
83320 KB |
Output is correct |
3 |
Correct |
47 ms |
83448 KB |
Output is correct |
4 |
Correct |
46 ms |
83320 KB |
Output is correct |
5 |
Correct |
47 ms |
83320 KB |
Output is correct |
6 |
Correct |
47 ms |
83420 KB |
Output is correct |
7 |
Correct |
47 ms |
83320 KB |
Output is correct |
8 |
Correct |
46 ms |
83320 KB |
Output is correct |
9 |
Correct |
48 ms |
83320 KB |
Output is correct |
10 |
Correct |
46 ms |
83320 KB |
Output is correct |
11 |
Execution timed out |
3094 ms |
90488 KB |
Time limit exceeded |
12 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
47 ms |
83320 KB |
Output is correct |
2 |
Execution timed out |
3100 ms |
85484 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |