rt。
输入 copy 的这个,输出 copy 的这个。还是 11 分 pwp。
#include<bits/stdc++.h>
using namespace std;
//#define int long long
#define re register
#define il inline
#define pii pair<int,int>
#define x first
#define y second
#define gc getchar()
#define rd read()
#define debug() puts("------------")
namespace yzqwq{
il int qmi(int a,int b,int p){
int ans=1;
while(b){
if(b&1) ans=ans*a%p;
a=a*a%p,b>>=1;
}
return ans;
}
il auto max(auto a,auto b){return (a>b?a:b);}
il auto min(auto a,auto b){return (a<b?a:b);}
il int gcd(int a,int b){
if(!b) return a;
return gcd(b,a%b);
}
il int lcm(int a,int b){
return a/gcd(a,b)*b;
}
il void exgcd(int a,int b,int &x,int &y){
if(!b) return x=1,y=0,void(0);
exgcd(b,a%b,x,y);
int t=x;
x=y,y=t-a/b*x;
return ;
}
mt19937 rnd(time(0));
}
using namespace yzqwq;
int nail;
string str;
int read(){
if(nail>=str.size())return 0;
int b=0;
while(nail<str.size() and (str[nail]<'0' or str[nail]>'9'))nail++;
while(nail<str.size() and str[nail]>='0' and str[nail]<='9'){
b=b*10+str[nail]-'0';
nail++;
}
return b;
}
const int N=1e5+10;
int n,m,s,t;
int ne[N<<1],e[N<<1],w[N<<1],h[N],h2[N],idx=1;
int dep[N],vis[N];
int sum,ans;
//string str;
il void add(int a,int b,int c){
ne[++idx]=h[a],e[idx]=b,w[idx]=c,h[a]=idx;
ne[++idx]=h[b],e[idx]=a,w[idx]=0,h[b]=idx;
}
il bool bfs(){
for(re int i=1;i<N;++i)
h2[i]=h[i],
dep[i]=1e9,vis[i]=0;
queue<int> qu;
qu.push(s),dep[s]=0,vis[s]=1;
while(!qu.empty()){
int now=qu.front();qu.pop();
for(re int i=h[now];i;i=ne[i]){
int j=e[i];
if(dep[j]>dep[now]+1&&w[i]){
dep[j]=dep[now]+1;
if(!vis[j]) vis[j]=1,qu.push(j);
}
}
}
if(dep[t]<1e9) return 1;
return 0;
}
il int dfs(int now,int Min){
if(now==t) return ans+=Min,Min;
int use=0;
for(re int i=h2[now];i;i=ne[i]){
int j=e[i];h2[now]=i;
if(dep[j]==dep[now]+1&&w[i]){
int use_=dfs(j,min(Min-use,w[i]));
if(use_<0) continue;
use+=use_;
w[i]-=use_,w[i^1]+=use_;
if(use==Min) return use;
}
}
return use;
}
il void dinic(){
while(bfs()) dfs(s,1e9);
return ;
}
il void solve(){
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
cin>>m>>n;
s=10001,t=10002;
getline(cin,str);
for(re int i=1;i<=m;++i){
// cout<<i<<":";
nail=0;
getline(cin,str);
int x=rd;sum+=x;
add(s,i,x);
int y;
while(1){
y=rd;
if(!y) break;
add(i,y+m,1e9);
}
}
for(re int i=1;i<=n;++i){
int x;cin>>x;
add(m+i,t,x);
}
dinic();
for(re int i=1;i<=m;++i)
if(dep[i]!=-1) printf("%d ",i);
puts("");
for(re int i=1;i<=n;++i)
if(dep[i+m]!=-1) printf("%d ",i);
printf("\n%d",sum-ans);
return ;
}
signed main(){
// freopen(".in","r",stdin);
// freopen(".out","w",stdout);
int t=1;while(t--)
solve();
return 0;
}