[连锁商店](https://codeforces.com/gym/103389/problem/C)
如果 1-2 ,2-3,1-3,则可以把边1-3去掉不影响答案
#pragma GCC optimize(2)
#pragma GCC optimize(3,"Ofast","inline")
#include<bits/stdc++.h>
#define int long long
#define fi first
#define se second
#define pb push_back
#define pii pair<int,int>
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
const int inf=8e18;
const int maxn=2e5+100;
int c[maxn],w[maxn];
int ans[maxn];
int mh[50][50];
vector<int>g[maxn];
int sum;
bitset<37> bt;
void dfs(int x,bitset<37> bt,int res)
{
if(x==1)
{
sum=max(sum,res);
return ;
}
if(ans[x]+res<sum)return ;
for(auto it:g[x])
{
if(bt[c[it]]==0)
{
bt[c[it]]=1;
dfs(it,bt,res+w[c[it]]);
bt[c[it]]=0;
}
else dfs(it,bt,res);
}
}
signed main()
{
IOS
int n,m;
cin>>n>>m;
for(int i =1;i<=n;i++)
{
cin>>c[i];
}
for(int i=1;i<=n;i++)
{
cin>>w[i];
}
for(int i=1;i<=m;i++)
{
int x,y;
cin>>x>>y;
mh[x][y]=1;
//g[y].pb(x);
}
for(int i=1;i<=n;i++)
{
for(int j=i+1;j<=n;j++)
{
for(int k=i+1;k<j;k++)
{
if(mh[i][j]&&mh[i][k]&&mh[k][j])mh[i][j]=0;
}
}
}
for(int i=1;i<=n;i++)
{
for(int j=i+1;j<=n;j++)
{
if(mh[i][j]) g[j].pb(i);
}
}
for(int i=1;i<=n;i++)
{
bt=0;
bt[c[i]]=1;
int res=w[c[i]];
sum=res;
dfs(i,bt,res);
ans[i]=sum;
cout<<sum<<"\n";
}
}