Submission #208434

# Submission time Handle Problem Language Result Execution time Memory
208434 2020-03-11T08:03:59 Z Fasho Paths (BOI18_paths) C++14
53 / 100
227 ms 60128 KB
#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

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
1 Correct 34 ms 53624 KB Output is correct
2 Correct 35 ms 53624 KB Output is correct
3 Correct 34 ms 53624 KB Output is correct
4 Correct 35 ms 53624 KB Output is correct
5 Correct 35 ms 53624 KB Output is correct
6 Correct 33 ms 53624 KB Output is correct
7 Correct 35 ms 53624 KB Output is correct
8 Correct 34 ms 53624 KB Output is correct
9 Correct 33 ms 53496 KB Output is correct
10 Correct 34 ms 53624 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 112 ms 60128 KB Output is correct
2 Correct 91 ms 59256 KB Output is correct
3 Incorrect 39 ms 54776 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 34 ms 53624 KB Output is correct
2 Correct 35 ms 53624 KB Output is correct
3 Correct 34 ms 53624 KB Output is correct
4 Correct 35 ms 53624 KB Output is correct
5 Correct 35 ms 53624 KB Output is correct
6 Correct 33 ms 53624 KB Output is correct
7 Correct 35 ms 53624 KB Output is correct
8 Correct 34 ms 53624 KB Output is correct
9 Correct 33 ms 53496 KB Output is correct
10 Correct 34 ms 53624 KB Output is correct
11 Correct 112 ms 60128 KB Output is correct
12 Correct 91 ms 59256 KB Output is correct
13 Incorrect 39 ms 54776 KB Output isn't correct
14 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 35 ms 53624 KB Output is correct
2 Correct 61 ms 55396 KB Output is correct
3 Correct 54 ms 55416 KB Output is correct
4 Correct 135 ms 58488 KB Output is correct
5 Correct 110 ms 59252 KB Output is correct
6 Correct 227 ms 58596 KB Output is correct
7 Correct 54 ms 55416 KB Output is correct
8 Correct 168 ms 58488 KB Output is correct
9 Correct 108 ms 59376 KB Output is correct
10 Correct 143 ms 59380 KB Output is correct
11 Correct 165 ms 56948 KB Output is correct
12 Correct 101 ms 58224 KB Output is correct
13 Correct 159 ms 57384 KB Output is correct
14 Correct 205 ms 58616 KB Output is correct
15 Correct 155 ms 58616 KB Output is correct
16 Correct 33 ms 53624 KB Output is correct
17 Correct 33 ms 53624 KB Output is correct
18 Correct 35 ms 53624 KB Output is correct
19 Correct 33 ms 53624 KB Output is correct
20 Correct 34 ms 53624 KB Output is correct
21 Correct 33 ms 53560 KB Output is correct
22 Correct 33 ms 53624 KB Output is correct
23 Correct 36 ms 53756 KB Output is correct
24 Correct 33 ms 53552 KB Output is correct
25 Correct 33 ms 53496 KB Output is correct