#include<bits/stdc++.h>
using namespace std;
#define s second
#define f first
typedef long long ll;
typedef pair<ll,pair<ll,ll> > pii;
ll a[2000005];
ll get(ll x){
if(a[x]==x)return x;
return a[x]=get(a[x]);
}
void join(ll x,ll y){
a[get(x)]=a[get(y)];
}
int main(){
ll n,mm,k;
cin>>n>>mm>>k;
map<int,int>m;
for(ll i=1;i<=k;i++){
ll x;
cin>>x;
m[i]=x;
}
for(ll i=1;i<=n;i++)a[i]=i;
vector<pii>v,res;
while(mm--){
ll s=0;
ll u,vv,l;
cin>>u>>vv>>l;
while(l--){
ll x;
cin>>x;
s|=(1<<(x));
}
v.push_back({s,{u,vv}});
}
sort(v.begin(),v.end());
ll sum=0;
for(ll i=0;i<v.size();i++){
pii it=v[i];
if(a[get(it.s.f)]!=a[get(it.s.s)]){
join(it.s.f,it.s.s);
res.push_back(it);
sum|=it.f;
}
}
if(res.size()!=(n-1))cout<<-1<<endl;
else {ll aa=0;
for(ll i=1;i<=k;i++)if(sum&(1<<i))aa+=m[i];
cout<<aa<<endl;
}
}
I2luY2x1ZGU8Yml0cy9zdGRjKysuaD4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKI2RlZmluZSBzIHNlY29uZAojZGVmaW5lIGYgZmlyc3QKdHlwZWRlZiBsb25nIGxvbmcgbGw7CnR5cGVkZWYgcGFpcjxsbCxwYWlyPGxsLGxsPiA+IHBpaTsKbGwgYVsyMDAwMDA1XTsKbGwgZ2V0KGxsIHgpewogICAgaWYoYVt4XT09eClyZXR1cm4geDsKICAgIHJldHVybiBhW3hdPWdldChhW3hdKTsKfQp2b2lkIGpvaW4obGwgeCxsbCB5KXsKICAgIGFbZ2V0KHgpXT1hW2dldCh5KV07Cn0KaW50IG1haW4oKXsKICAgIGxsIG4sbW0sazsKICAgIGNpbj4+bj4+bW0+Pms7CiAgICBtYXA8aW50LGludD5tOwogICAgZm9yKGxsIGk9MTtpPD1rO2krKyl7CiAgICAgICAgbGwgeDsKICAgICAgICBjaW4+Png7CiAgICAgICAgbVtpXT14OwogICAgfQogICAgZm9yKGxsIGk9MTtpPD1uO2krKylhW2ldPWk7CiAgICB2ZWN0b3I8cGlpPnYscmVzOwogICAgd2hpbGUobW0tLSl7CiAgICAgICAgbGwgcz0wOwogICAgICAgIGxsIHUsdnYsbDsKICAgICAgICBjaW4+PnU+PnZ2Pj5sOwogICAgICAgIHdoaWxlKGwtLSl7CiAgICAgICAgICAgIGxsIHg7CiAgICAgICAgICAgIGNpbj4+eDsKICAgICAgICAgICAgc3w9KDE8PCh4KSk7CiAgICAgICAgfQogICAgICAgIHYucHVzaF9iYWNrKHtzLHt1LHZ2fX0pOwogICAgfQogICAgc29ydCh2LmJlZ2luKCksdi5lbmQoKSk7CiAgICBsbCBzdW09MDsKICAgIGZvcihsbCBpPTA7aTx2LnNpemUoKTtpKyspewogICAgICAgIHBpaSBpdD12W2ldOwogICAgICAgIGlmKGFbZ2V0KGl0LnMuZildIT1hW2dldChpdC5zLnMpXSl7CiAgICAgICAgICAgIGpvaW4oaXQucy5mLGl0LnMucyk7CiAgICAgICAgICAgIHJlcy5wdXNoX2JhY2soaXQpOwogICAgICAgICAgICBzdW18PWl0LmY7CiAgICAgICAgfQogICAgfQogICAgaWYocmVzLnNpemUoKSE9KG4tMSkpY291dDw8LTE8PGVuZGw7CiAgICBlbHNlIHtsbCBhYT0wOwogICAgZm9yKGxsIGk9MTtpPD1rO2krKylpZihzdW0mKDE8PGkpKWFhKz1tW2ldOwogICAgICAgIGNvdXQ8PGFhPDxlbmRsOwogICAgfQogICAgCn0=