#include <bits/stdc++.h>
#define N 300005
#define ll long long int
#define MP make_pair
#define pb push_back
#define ppb pop_back
#define sp " "
#define endl "\n"
#define fi first
#define se second
#define ii pair<int,int>
#define lli pair<ll,ll>
#define fast cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(false)
#define fast2 freopen ("badhair.gir","r",stdin);freopen ("badhair.cik","w",stdout);
#define mod 1000000007
#define fs(x,y) for(ll i=1;i<=y;i++) cin>>x[i]
#define fo(i,x,y) for(ll i=x;i<=y;i++)
#define INF 1000000000005
#define ull unsigned long long int
using namespace std;
ll n,m,ar[N],sum,t,dp[N][32],pw[N],k;
vector<int> v[N];
ll f(int ind,int mask)
{
// cout<<ind<<sp<<mask<<endl;
if(dp[ind][mask]!=-1)
return dp[ind][mask];
if((pw[ar[ind]] & mask))
return dp[ind][mask]=0;
ll x=mask;
mask=(mask|pw[ar[ind]]);
ll top=1;
for(int i=0;i<v[ind].size();i++)
{
// if(ind==2)
// cout<<"[d]"<<sp<<v[ind][i]<<sp<<mask<<sp<<f(v[ind][i],mask)<<endl;
top+=f(v[ind][i],mask);
}
return dp[ind][x]=top;
}
int main()
{
fast;
cin>>n>>m>>k;
// cout<<endl;
pw[0]=1;
fo(i,1,5)
pw[i]=pw[i-1]*2;
memset(dp,-1,sizeof(dp));
fo(i,1,6)
pw[i]=pw[i-1]*2;
fs(ar,n);
for(int i=1;i<=m;i++)
{
int a,b;
cin>>a>>b;
v[a].pb(b);
v[b].pb(a);
}
fo(i,1,n)
{
ll x=f(i,0);
sum+=x;
// cout<<endl;
// cout<<x<<endl;
}
// cout<<dp[1][4]<<endl;
// sum=f(2,0);
// cout<<sum<<endl;
// cout<<endl;
sum-=n;
cout<<sum;
}
Compilation message
paths.cpp: In function 'long long int f(int, int)':
paths.cpp:36:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0;i<v[ind].size();i++)
~^~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
50 ms |
82552 KB |
Output is correct |
2 |
Correct |
47 ms |
82556 KB |
Output is correct |
3 |
Correct |
49 ms |
82552 KB |
Output is correct |
4 |
Correct |
48 ms |
82552 KB |
Output is correct |
5 |
Correct |
49 ms |
82556 KB |
Output is correct |
6 |
Correct |
48 ms |
82552 KB |
Output is correct |
7 |
Correct |
49 ms |
82552 KB |
Output is correct |
8 |
Correct |
49 ms |
82808 KB |
Output is correct |
9 |
Correct |
49 ms |
82552 KB |
Output is correct |
10 |
Correct |
48 ms |
82552 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
121 ms |
86392 KB |
Output is correct |
2 |
Correct |
109 ms |
86008 KB |
Output is correct |
3 |
Correct |
487 ms |
97332 KB |
Output is correct |
4 |
Correct |
172 ms |
90616 KB |
Output is correct |
5 |
Correct |
158 ms |
90616 KB |
Output is correct |
6 |
Correct |
340 ms |
95284 KB |
Output is correct |
7 |
Correct |
479 ms |
97656 KB |
Output is correct |
8 |
Correct |
437 ms |
98428 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
50 ms |
82552 KB |
Output is correct |
2 |
Correct |
47 ms |
82556 KB |
Output is correct |
3 |
Correct |
49 ms |
82552 KB |
Output is correct |
4 |
Correct |
48 ms |
82552 KB |
Output is correct |
5 |
Correct |
49 ms |
82556 KB |
Output is correct |
6 |
Correct |
48 ms |
82552 KB |
Output is correct |
7 |
Correct |
49 ms |
82552 KB |
Output is correct |
8 |
Correct |
49 ms |
82808 KB |
Output is correct |
9 |
Correct |
49 ms |
82552 KB |
Output is correct |
10 |
Correct |
48 ms |
82552 KB |
Output is correct |
11 |
Correct |
121 ms |
86392 KB |
Output is correct |
12 |
Correct |
109 ms |
86008 KB |
Output is correct |
13 |
Correct |
487 ms |
97332 KB |
Output is correct |
14 |
Correct |
172 ms |
90616 KB |
Output is correct |
15 |
Correct |
158 ms |
90616 KB |
Output is correct |
16 |
Correct |
340 ms |
95284 KB |
Output is correct |
17 |
Correct |
479 ms |
97656 KB |
Output is correct |
18 |
Correct |
437 ms |
98428 KB |
Output is correct |
19 |
Correct |
127 ms |
89080 KB |
Output is correct |
20 |
Correct |
111 ms |
88320 KB |
Output is correct |
21 |
Correct |
490 ms |
97784 KB |
Output is correct |
22 |
Correct |
177 ms |
90616 KB |
Output is correct |
23 |
Correct |
163 ms |
90616 KB |
Output is correct |
24 |
Correct |
322 ms |
95336 KB |
Output is correct |
25 |
Correct |
491 ms |
97784 KB |
Output is correct |
26 |
Correct |
435 ms |
98424 KB |
Output is correct |
27 |
Correct |
122 ms |
88312 KB |
Output is correct |
28 |
Correct |
149 ms |
89976 KB |
Output is correct |
29 |
Correct |
610 ms |
97784 KB |
Output is correct |
30 |
Correct |
446 ms |
93676 KB |
Output is correct |
31 |
Correct |
479 ms |
93740 KB |
Output is correct |
32 |
Correct |
624 ms |
97784 KB |
Output is correct |
33 |
Correct |
50 ms |
82552 KB |
Output is correct |
34 |
Correct |
49 ms |
82552 KB |
Output is correct |
35 |
Correct |
49 ms |
82552 KB |
Output is correct |
36 |
Correct |
49 ms |
82552 KB |
Output is correct |
37 |
Correct |
51 ms |
82552 KB |
Output is correct |
38 |
Correct |
48 ms |
82556 KB |
Output is correct |
39 |
Correct |
50 ms |
82552 KB |
Output is correct |
40 |
Correct |
49 ms |
82552 KB |
Output is correct |
41 |
Correct |
50 ms |
82552 KB |
Output is correct |
42 |
Correct |
47 ms |
82528 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
48 ms |
82552 KB |
Output is correct |
2 |
Incorrect |
71 ms |
83576 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |