# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
208458 | tleontest1 | Paths (BOI18_paths) | C++14 | 623 ms | 118144 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
using namespace std;
typedef long long lo;
typedef pair< lo,lo > PII;
#define fi first
#define se second
#define int long long
#define mp make_pair
#define pb push_back
#define fio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define FOR for(int i=1;i<=n;i++)
#define mid ((start+end)/2)
#define ort ((bas+son)/2)
const lo MAX = -1000000000000000000;
const lo MIN = 1000000000000000000;
const lo inf = 1000000000;
const lo KOK = 100000;
const lo LOG = 30;
const lo li = 300005;
const lo mod = 1000000007;
int n,m,b[li],a[li],k,flag,t,dp[li][(1<<5)+3];
int cev;
string s;
map<vector<int>,int> mpp[li];
vector<int> v[li],vec;
inline int dfs(int node,int ata,int mask){
int cevv=0;
if(mask==(1<<5)-1)return 1;
if(~dp[node][mask])return dp[node][mask];
if(mask!=(1<<0) && mask!=(1<<1) && mask!=(1<<2) && mask!=(1<<3) && mask!=(1<<4) && mask)cevv+=dfs(node,ata,(1<<5)-1);
for(int i=0;i<(int)v[node].size();i++){
int go=v[node][i];
//~ if(go==ata)continue;
//~ cevv+=dfs(go,node,mask);
if((mask&(1<<(a[go]-1)))==0)cevv+=dfs(go,node,(mask|(1<<(a[go]-1))));
}
return dp[node][mask]=cevv;
}
main(void){
scanf("%lld %lld %lld",&n,&m,&k);
FOR scanf("%lld",&a[i]);
for(int i=1;i<=m;i++){
int x,y;
scanf("%lld %lld",&x,&y);
v[x].pb(y);
v[y].pb(x);
}
memset(dp,-1,sizeof(dp));
FOR{
cev+=dfs(i,0,(1<<(a[i]-1)));
}
printf("%lld\n",cev);
return 0;
}
Compilation message (stderr)
# | 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... |