/*************************************
* author: Pham Huy Khanh *
*************************************/
#include <bits/stdc++.h>
#define ll long long
#define FOR(i,a,b) for (int i = (a), _b = (b); i <= _b; i++)
#define FOD(i,b,a) for (int i = (b), _a = (a); i >= _a; i--)
#define REP(i,n) for (int i = (0), _n = (n); i < _n; i++)
#define ALL(v) (v).begin(), (v).end()
#define BIT(x, i) (((x) >> (i)) & 1)
#define MASK(i) (1LL << (i))
#define CNTBIT(x) __builtin_popcountll(x)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define left ___left
#define right ___right
#define pii pair<int, int>
#define DEBUG(n, a) FOR (i, 1, n) cout << a[i] << ' '; cout << endl;
#define endl "\n"
using namespace std;
template<class X, class Y> bool maximize(X &x, Y y){ if (x < y){ x = y; return true; } return false; }
template<class X, class Y> bool minimize(X &x, Y y){ if (x > y){ x = y; return true; } return false; }
#define gogobruhbruh ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
#define file(name) if (fopen (name".inp", "r")) { freopen (name".inp", "r", stdin); freopen (name".out", "w", stdout); }
const int MOD = 1e9 + 7;
void sub(int &a, int b){ if ((a -= b) < 0) a += MOD; }
int muti(int a, int b){ return 1LL * a * b % MOD; }
int Pow(int x, int y){ int res = 1; for (; y; y >>= 1){ if (y & 1) res = muti(res, x); x = muti(x, x); } return res; }
const int MAX = 3e5 + 5;
const int INF = 1e9 + 7;
int numNode, numEdge, numCol;
int col[MAX];
ll dp[MAX][MASK(5)];
vector<int> edge[MAX];
bool vis[MAX][MASK(5)];
void dfs(int u, int mask){
vis[u][mask] = 1;
int nxt = mask ^ MASK(col[u]);
for (int v : edge[u]) if (BIT(nxt, col[v])){
if (!vis[v][nxt]) dfs(v, nxt);
dp[u][mask] += dp[v][nxt];
}
}
void solve(){
ll res = 0;
FOR (i, 1, numNode){
REP (j, MASK(numCol)) if (CNTBIT(j) > 1 && BIT(j, col[i])){
if (!vis[i][j]) dfs(i, j);
res += dp[i][j];
}
}
cout << res;
}
void read(){
cin >> numNode >> numEdge >> numCol;
FOR (i, 1, numNode) cin >> col[i], col[i]--, dp[i][MASK(col[i])] = 1;
FOR (i, 1, numEdge){
static int u, v;
cin >> u >> v;
if (col[u] == col[v]) continue;
edge[u].eb(v);
edge[v].eb(u);
}
}
int main(){
gogobruhbruh
file("main")
int test = 1;
// cin >> test;
while (test--)
read(),
solve();
}
Compilation message
paths.cpp: In function 'int main()':
paths.cpp:29:61: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
29 | #define file(name) if (fopen (name".inp", "r")) { freopen (name".inp", "r", stdin); freopen (name".out", "w", stdout); }
| ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
paths.cpp:79:5: note: in expansion of macro 'file'
79 | file("main")
| ^~~~
paths.cpp:29:95: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
29 | #define file(name) if (fopen (name".inp", "r")) { freopen (name".inp", "r", stdin); freopen (name".out", "w", stdout); }
| ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
paths.cpp:79:5: note: in expansion of macro 'file'
79 | file("main")
| ^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
10576 KB |
Output is correct |
2 |
Correct |
3 ms |
10576 KB |
Output is correct |
3 |
Correct |
3 ms |
10588 KB |
Output is correct |
4 |
Correct |
2 ms |
10576 KB |
Output is correct |
5 |
Correct |
2 ms |
10576 KB |
Output is correct |
6 |
Correct |
2 ms |
10576 KB |
Output is correct |
7 |
Correct |
2 ms |
10576 KB |
Output is correct |
8 |
Correct |
3 ms |
10576 KB |
Output is correct |
9 |
Correct |
2 ms |
10576 KB |
Output is correct |
10 |
Correct |
3 ms |
10576 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
57 ms |
18492 KB |
Output is correct |
2 |
Correct |
38 ms |
16876 KB |
Output is correct |
3 |
Correct |
159 ms |
104528 KB |
Output is correct |
4 |
Correct |
58 ms |
25416 KB |
Output is correct |
5 |
Correct |
38 ms |
22116 KB |
Output is correct |
6 |
Correct |
127 ms |
77900 KB |
Output is correct |
7 |
Correct |
183 ms |
104524 KB |
Output is correct |
8 |
Correct |
163 ms |
105288 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
10576 KB |
Output is correct |
2 |
Correct |
3 ms |
10576 KB |
Output is correct |
3 |
Correct |
3 ms |
10588 KB |
Output is correct |
4 |
Correct |
2 ms |
10576 KB |
Output is correct |
5 |
Correct |
2 ms |
10576 KB |
Output is correct |
6 |
Correct |
2 ms |
10576 KB |
Output is correct |
7 |
Correct |
2 ms |
10576 KB |
Output is correct |
8 |
Correct |
3 ms |
10576 KB |
Output is correct |
9 |
Correct |
2 ms |
10576 KB |
Output is correct |
10 |
Correct |
3 ms |
10576 KB |
Output is correct |
11 |
Correct |
57 ms |
18492 KB |
Output is correct |
12 |
Correct |
38 ms |
16876 KB |
Output is correct |
13 |
Correct |
159 ms |
104528 KB |
Output is correct |
14 |
Correct |
58 ms |
25416 KB |
Output is correct |
15 |
Correct |
38 ms |
22116 KB |
Output is correct |
16 |
Correct |
127 ms |
77900 KB |
Output is correct |
17 |
Correct |
183 ms |
104524 KB |
Output is correct |
18 |
Correct |
163 ms |
105288 KB |
Output is correct |
19 |
Correct |
49 ms |
18504 KB |
Output is correct |
20 |
Correct |
41 ms |
16976 KB |
Output is correct |
21 |
Correct |
239 ms |
104480 KB |
Output is correct |
22 |
Correct |
62 ms |
25592 KB |
Output is correct |
23 |
Correct |
36 ms |
22088 KB |
Output is correct |
24 |
Correct |
165 ms |
77836 KB |
Output is correct |
25 |
Correct |
226 ms |
104532 KB |
Output is correct |
26 |
Correct |
209 ms |
105288 KB |
Output is correct |
27 |
Correct |
51 ms |
18512 KB |
Output is correct |
28 |
Correct |
76 ms |
18516 KB |
Output is correct |
29 |
Correct |
263 ms |
105032 KB |
Output is correct |
30 |
Correct |
128 ms |
63424 KB |
Output is correct |
31 |
Correct |
141 ms |
63424 KB |
Output is correct |
32 |
Correct |
212 ms |
104948 KB |
Output is correct |
33 |
Correct |
2 ms |
10576 KB |
Output is correct |
34 |
Correct |
2 ms |
10592 KB |
Output is correct |
35 |
Correct |
2 ms |
10588 KB |
Output is correct |
36 |
Correct |
2 ms |
10724 KB |
Output is correct |
37 |
Correct |
2 ms |
10576 KB |
Output is correct |
38 |
Correct |
2 ms |
10576 KB |
Output is correct |
39 |
Correct |
2 ms |
10576 KB |
Output is correct |
40 |
Correct |
2 ms |
10576 KB |
Output is correct |
41 |
Correct |
2 ms |
10576 KB |
Output is correct |
42 |
Correct |
2 ms |
10576 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
10576 KB |
Output is correct |
2 |
Correct |
25 ms |
12576 KB |
Output is correct |
3 |
Correct |
14 ms |
12368 KB |
Output is correct |
4 |
Correct |
44 ms |
44108 KB |
Output is correct |
5 |
Correct |
38 ms |
44248 KB |
Output is correct |
6 |
Correct |
89 ms |
44200 KB |
Output is correct |
7 |
Correct |
16 ms |
12368 KB |
Output is correct |
8 |
Correct |
78 ms |
44084 KB |
Output is correct |
9 |
Correct |
46 ms |
44392 KB |
Output is correct |
10 |
Correct |
67 ms |
45156 KB |
Output is correct |
11 |
Correct |
51 ms |
29380 KB |
Output is correct |
12 |
Correct |
53 ms |
37448 KB |
Output is correct |
13 |
Correct |
51 ms |
29512 KB |
Output is correct |
14 |
Correct |
85 ms |
44360 KB |
Output is correct |
15 |
Correct |
72 ms |
44304 KB |
Output is correct |
16 |
Correct |
2 ms |
10576 KB |
Output is correct |
17 |
Correct |
3 ms |
10576 KB |
Output is correct |
18 |
Correct |
2 ms |
10576 KB |
Output is correct |
19 |
Correct |
2 ms |
10576 KB |
Output is correct |
20 |
Correct |
2 ms |
10576 KB |
Output is correct |
21 |
Correct |
2 ms |
10576 KB |
Output is correct |
22 |
Correct |
3 ms |
10576 KB |
Output is correct |
23 |
Correct |
2 ms |
10576 KB |
Output is correct |
24 |
Correct |
3 ms |
10576 KB |
Output is correct |
25 |
Correct |
2 ms |
10576 KB |
Output is correct |