#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define FOR(i,a) for (int i=0;i<(a);++i)
#define FORD(i,a) for (int i=(a)-1;i>=0;i--)
#define FORT(i,a,b) for (int i=(a);i<=(b);++i)
#define FORTD(i,b,a) for (int i=(b);i>=(a);--i)
#define trav(i,v) for (auto i : v)
#define all(v) v.begin(),v.end()
#define ad push_back
#define fr first
#define sc second
#define mpr(a,b) make_pair(a,b)
#define pir pair<int,int>
#define all(v) v.begin(),v.end()
#define make_unique(v) v.erase(unique(all(v),v.end()))
#define fastio ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define dbg(x);
#define dbgv(v);
#define srng mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define y1 EsiHancagorcRepa
#ifdef ALEXPC
#define dbg(x); cout<<#x<<" = "<<x<<endl
#define dbgv(v); cout<<#v<<" = ["; trav(tv,v)cout<<"tv,";cout<<"]"<<endl
#endif
const int N=3*1e5+6;
const ll MOD=1000*1000*1000+7;
int f[N];
ll dp[N][32];
vector<int> g[N];
void rec(int v,int mask){
if (dp[v][mask]!=-1)return;
dp[v][mask]=1;
trav(to,g[v]){
if (f[to]&mask)continue;
rec(to,mask+f[to]);
dp[v][mask]+=dp[to][mask+f[to]];
//cout<<v<<" "<<mask<<" "<<dp[to][ma]
}
}
int main(){
fastio;
srng;
int n, m, k;
cin >> n >> m >> k;
FOR(i, n) {
cin >> f[i+1];
f[i+1]--;
f[i+1]=(1<<f[i+1]);
FOR(j,31)dp[i+1][j]=-1;
}
FOR(i, m) {
int a, b;
cin >> a >> b;
g[a].push_back(b);
g[b].push_back(a);
}
ll ans=0;
FORT(i,1,n){
rec(i,f[i]);
ans+=dp[i][f[i]];
}
cout<<ans-n<<endl;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
7424 KB |
Output is correct |
2 |
Correct |
9 ms |
7424 KB |
Output is correct |
3 |
Correct |
9 ms |
7424 KB |
Output is correct |
4 |
Correct |
9 ms |
7424 KB |
Output is correct |
5 |
Correct |
10 ms |
7424 KB |
Output is correct |
6 |
Correct |
11 ms |
7424 KB |
Output is correct |
7 |
Correct |
10 ms |
7424 KB |
Output is correct |
8 |
Correct |
9 ms |
7424 KB |
Output is correct |
9 |
Correct |
10 ms |
7424 KB |
Output is correct |
10 |
Correct |
9 ms |
7424 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
146 ms |
15224 KB |
Output is correct |
2 |
Correct |
88 ms |
13404 KB |
Output is correct |
3 |
Correct |
503 ms |
96668 KB |
Output is correct |
4 |
Correct |
259 ms |
22908 KB |
Output is correct |
5 |
Correct |
201 ms |
23012 KB |
Output is correct |
6 |
Correct |
360 ms |
69488 KB |
Output is correct |
7 |
Correct |
582 ms |
96632 KB |
Output is correct |
8 |
Correct |
483 ms |
97280 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
7424 KB |
Output is correct |
2 |
Correct |
9 ms |
7424 KB |
Output is correct |
3 |
Correct |
9 ms |
7424 KB |
Output is correct |
4 |
Correct |
9 ms |
7424 KB |
Output is correct |
5 |
Correct |
10 ms |
7424 KB |
Output is correct |
6 |
Correct |
11 ms |
7424 KB |
Output is correct |
7 |
Correct |
10 ms |
7424 KB |
Output is correct |
8 |
Correct |
9 ms |
7424 KB |
Output is correct |
9 |
Correct |
10 ms |
7424 KB |
Output is correct |
10 |
Correct |
9 ms |
7424 KB |
Output is correct |
11 |
Correct |
146 ms |
15224 KB |
Output is correct |
12 |
Correct |
88 ms |
13404 KB |
Output is correct |
13 |
Correct |
503 ms |
96668 KB |
Output is correct |
14 |
Correct |
259 ms |
22908 KB |
Output is correct |
15 |
Correct |
201 ms |
23012 KB |
Output is correct |
16 |
Correct |
360 ms |
69488 KB |
Output is correct |
17 |
Correct |
582 ms |
96632 KB |
Output is correct |
18 |
Correct |
483 ms |
97280 KB |
Output is correct |
19 |
Correct |
95 ms |
15244 KB |
Output is correct |
20 |
Correct |
74 ms |
13476 KB |
Output is correct |
21 |
Correct |
509 ms |
96632 KB |
Output is correct |
22 |
Correct |
155 ms |
22904 KB |
Output is correct |
23 |
Correct |
129 ms |
22880 KB |
Output is correct |
24 |
Correct |
298 ms |
69592 KB |
Output is correct |
25 |
Correct |
459 ms |
96508 KB |
Output is correct |
26 |
Correct |
443 ms |
97144 KB |
Output is correct |
27 |
Correct |
88 ms |
13304 KB |
Output is correct |
28 |
Correct |
135 ms |
16632 KB |
Output is correct |
29 |
Correct |
597 ms |
96668 KB |
Output is correct |
30 |
Correct |
423 ms |
55640 KB |
Output is correct |
31 |
Correct |
558 ms |
55780 KB |
Output is correct |
32 |
Correct |
654 ms |
96708 KB |
Output is correct |
33 |
Correct |
10 ms |
7424 KB |
Output is correct |
34 |
Correct |
10 ms |
7424 KB |
Output is correct |
35 |
Correct |
8 ms |
7424 KB |
Output is correct |
36 |
Correct |
9 ms |
7424 KB |
Output is correct |
37 |
Correct |
9 ms |
7424 KB |
Output is correct |
38 |
Correct |
10 ms |
7424 KB |
Output is correct |
39 |
Correct |
8 ms |
7424 KB |
Output is correct |
40 |
Correct |
8 ms |
7424 KB |
Output is correct |
41 |
Correct |
9 ms |
7424 KB |
Output is correct |
42 |
Correct |
10 ms |
7424 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
7424 KB |
Output is correct |
2 |
Incorrect |
46 ms |
9316 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |