#include <bits/stdc++.h>
using namespace std;
#define f first
#define s second
#define pb push_back
#define ar array
#define all(x) x.begin(), x.end()
#define siz(x) (int) x.size()
#define uid(a, b) uniform_int_distribution<int>(a, b)(rng)
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define ROF(i, a, b) for(int i=(b-1); i>=(a); i--)
#define F0R(i, n) FOR(i, 0, n)
#define R0F(i, n) ROF(i, 0, n)
#define trav(x, y) for(auto&x:y)
using ll=long long;
using ld=long double;
using pii=pair<int, int>;
using pll=pair<ll, ll>;
using pli=pair<ll, int>;
using vi=vector<int>;
using vl=vector<ll>;
using vpii=vector<pii>;
template<class T> inline bool ckmin(T&a, const T&b) {return b<a?a=b,1:0;}
template<class T> inline bool ckmax(T&a, const T&b) {return b>a?a=b,1:0;}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const char nl='\n';
const int mxN=3e5+10;
const int MOD=1e9+7;
const ll infLL=1e18;
const ld eps=1e-6;
int n, m, k;
int col[mxN];
vi adj[mxN];
ll ans=0;
ll memo[mxN][1<<5];
ll dfs(int u, int msk){
if((1<<col[u])&msk)
return 0;
msk|=1<<col[u];
if(memo[u][msk]!=-1) return memo[u][msk];
memo[u][msk]=1;
trav(v, adj[u]){
memo[u][msk]+=dfs(v, msk);
}
return memo[u][msk];
}
int32_t main(){
cin.tie(0)->sync_with_stdio(0);
cin >> n >> m >> k;
memset(memo, -1, sizeof memo);
F0R(i, n) cin >> col[i], col[i]--;
F0R(i, m){
int e1, e2; cin >> e1 >> e2;
e1--; e2--;
adj[e1].pb(e2); adj[e2].pb(e1);
}
F0R(i, n){
ans+=dfs(i, 0);
}
cout << ans-n << nl;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
42 ms |
82500 KB |
Output is correct |
2 |
Correct |
43 ms |
82456 KB |
Output is correct |
3 |
Correct |
47 ms |
82584 KB |
Output is correct |
4 |
Correct |
42 ms |
82444 KB |
Output is correct |
5 |
Correct |
45 ms |
82496 KB |
Output is correct |
6 |
Correct |
42 ms |
82404 KB |
Output is correct |
7 |
Correct |
42 ms |
82504 KB |
Output is correct |
8 |
Correct |
42 ms |
82496 KB |
Output is correct |
9 |
Correct |
47 ms |
82488 KB |
Output is correct |
10 |
Correct |
43 ms |
82500 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
124 ms |
86108 KB |
Output is correct |
2 |
Correct |
109 ms |
88280 KB |
Output is correct |
3 |
Correct |
422 ms |
96712 KB |
Output is correct |
4 |
Correct |
186 ms |
90384 KB |
Output is correct |
5 |
Correct |
167 ms |
90400 KB |
Output is correct |
6 |
Correct |
289 ms |
94488 KB |
Output is correct |
7 |
Correct |
440 ms |
96400 KB |
Output is correct |
8 |
Correct |
398 ms |
97260 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
42 ms |
82500 KB |
Output is correct |
2 |
Correct |
43 ms |
82456 KB |
Output is correct |
3 |
Correct |
47 ms |
82584 KB |
Output is correct |
4 |
Correct |
42 ms |
82444 KB |
Output is correct |
5 |
Correct |
45 ms |
82496 KB |
Output is correct |
6 |
Correct |
42 ms |
82404 KB |
Output is correct |
7 |
Correct |
42 ms |
82504 KB |
Output is correct |
8 |
Correct |
42 ms |
82496 KB |
Output is correct |
9 |
Correct |
47 ms |
82488 KB |
Output is correct |
10 |
Correct |
43 ms |
82500 KB |
Output is correct |
11 |
Correct |
124 ms |
86108 KB |
Output is correct |
12 |
Correct |
109 ms |
88280 KB |
Output is correct |
13 |
Correct |
422 ms |
96712 KB |
Output is correct |
14 |
Correct |
186 ms |
90384 KB |
Output is correct |
15 |
Correct |
167 ms |
90400 KB |
Output is correct |
16 |
Correct |
289 ms |
94488 KB |
Output is correct |
17 |
Correct |
440 ms |
96400 KB |
Output is correct |
18 |
Correct |
398 ms |
97260 KB |
Output is correct |
19 |
Correct |
126 ms |
89000 KB |
Output is correct |
20 |
Correct |
113 ms |
88368 KB |
Output is correct |
21 |
Correct |
437 ms |
96532 KB |
Output is correct |
22 |
Correct |
152 ms |
90388 KB |
Output is correct |
23 |
Correct |
162 ms |
90412 KB |
Output is correct |
24 |
Correct |
322 ms |
94484 KB |
Output is correct |
25 |
Correct |
382 ms |
96528 KB |
Output is correct |
26 |
Correct |
409 ms |
97196 KB |
Output is correct |
27 |
Correct |
130 ms |
88404 KB |
Output is correct |
28 |
Correct |
183 ms |
89796 KB |
Output is correct |
29 |
Correct |
537 ms |
96536 KB |
Output is correct |
30 |
Correct |
411 ms |
93064 KB |
Output is correct |
31 |
Correct |
462 ms |
92864 KB |
Output is correct |
32 |
Correct |
524 ms |
96568 KB |
Output is correct |
33 |
Correct |
42 ms |
82500 KB |
Output is correct |
34 |
Correct |
42 ms |
82536 KB |
Output is correct |
35 |
Correct |
43 ms |
82408 KB |
Output is correct |
36 |
Correct |
44 ms |
82500 KB |
Output is correct |
37 |
Correct |
42 ms |
82468 KB |
Output is correct |
38 |
Correct |
43 ms |
82416 KB |
Output is correct |
39 |
Correct |
43 ms |
82500 KB |
Output is correct |
40 |
Correct |
43 ms |
82456 KB |
Output is correct |
41 |
Correct |
42 ms |
82484 KB |
Output is correct |
42 |
Correct |
43 ms |
82484 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
42 ms |
82432 KB |
Output is correct |
2 |
Correct |
88 ms |
83800 KB |
Output is correct |
3 |
Correct |
68 ms |
84312 KB |
Output is correct |
4 |
Correct |
142 ms |
86980 KB |
Output is correct |
5 |
Correct |
107 ms |
87872 KB |
Output is correct |
6 |
Correct |
164 ms |
87036 KB |
Output is correct |
7 |
Correct |
73 ms |
84328 KB |
Output is correct |
8 |
Correct |
153 ms |
87108 KB |
Output is correct |
9 |
Correct |
117 ms |
87792 KB |
Output is correct |
10 |
Correct |
146 ms |
87872 KB |
Output is correct |
11 |
Correct |
139 ms |
85580 KB |
Output is correct |
12 |
Correct |
114 ms |
86828 KB |
Output is correct |
13 |
Correct |
133 ms |
85836 KB |
Output is correct |
14 |
Correct |
163 ms |
87000 KB |
Output is correct |
15 |
Correct |
135 ms |
87112 KB |
Output is correct |
16 |
Correct |
42 ms |
82500 KB |
Output is correct |
17 |
Correct |
43 ms |
82428 KB |
Output is correct |
18 |
Correct |
42 ms |
82512 KB |
Output is correct |
19 |
Correct |
42 ms |
82492 KB |
Output is correct |
20 |
Correct |
42 ms |
82416 KB |
Output is correct |
21 |
Correct |
44 ms |
82496 KB |
Output is correct |
22 |
Correct |
42 ms |
82432 KB |
Output is correct |
23 |
Correct |
42 ms |
82492 KB |
Output is correct |
24 |
Correct |
41 ms |
82484 KB |
Output is correct |
25 |
Correct |
42 ms |
82492 KB |
Output is correct |