#include<bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
#define maxn 400005
const int inf=0x7fffffff;
int n,m,x,h[maxn],cnt=1,dep[maxn],bj,hh[maxn],cs[maxn],s=0,t,vis[maxn];
struct node {
int next,to,pd,w;
} e[maxn<<1];
void add(int u,int v,int w) {
e[++cnt].to=v;
e[cnt].next=h[u];
e[cnt].w=w;
h[u]=cnt;
}
bool bfs() {
memset(dep,-1,sizeof(dep));
queue<int> q;
q.push(0);
dep[0]=1;
while(!q.empty()) {
int x=q.front();
q.pop();
for(int i=h[x]; i; i=e[i].next) {
int v=e[i].to;
if(dep[v]==-1&&e[i].w) {
dep[v]=dep[x]+1;
q.push(v);
if(v==n+1)return 1;
}
}
}
return 0;
}
int dfs(int u,int flow){
if(u==n+1) return flow;
int rest=flow;
for(int i=h[u];i&&rest;i=e[i].next){
int v=e[i].to;
if(e[i].w&&dep[v]==dep[u]+1){
int tmp=dfs(v,min(rest,e[i].w));
if(!tmp) dep[v]=0;
rest-=tmp;
e[i].w-=tmp;
e[i^1].w+=tmp;
}
}
return flow-rest;
}
signed main() {
memset(h,-1,sizeof(h));
cin>>n>>m;
t=n+1;
for(int i=1;i<=n;i++)cin>>cs[i];
for(int i=1; i<=m; i++) {
int k;
cin>>k;
for(int j=1;j<=k;j++){
int x;
cin>>x;
if(!vis[x]){
add(0, i, cs[x]);
add(i, 0, 0);
}
else{
add(vis[x],i,inf);
add(i,vis[x],0);
}
vis[x]=i;
}
int nd;
cin>>nd;
add(i, n+1, nd);
add(n+1, i, 0);
}
int tmp=0,zdl=0;
while(bfs()) {
while(tmp=dfs(0,1e9))zdl+=tmp;
}
cout<<zdl;
return 0;
}
p.s 主要是看了一下发现好像没人跟我错的一样