This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define N 100005
#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][65],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 (stderr)
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++)
~^~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |