Skip to content

Instantly share code, notes, and snippets.

@latte0119
Created August 15, 2016 17:17
Show Gist options
  • Save latte0119/af14ab9ae5c83279e29a89db8849a49f to your computer and use it in GitHub Desktop.
Save latte0119/af14ab9ae5c83279e29a89db8849a49f to your computer and use it in GitHub Desktop.
#include<bits/stdc++.h>
using namespace std;
#define int long long
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define all(v) (v).begin(),(v).end()
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define pb push_back
#define fi first
#define se second
template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}
int N,E,T;
int W[300];
int G[1000],C[1000],S[1000][10];
int F[300];
signed main(){
cin>>N>>E>>T;
rep(i,N)cin>>W[i];
rep(i,E){
cin>>G[i]>>C[i];
G[i]--;
rep(j,C[i]){
cin>>S[i][j];
S[i][j]--;
}
}
fill_n(F,N,1001001001);
rep(i,N)if(W[i])F[i]=1;
for(int i=0;i<N;i++){
for(int j=0;j<E;j++){
vint v;
rep(k,C[j])v.pb(F[S[j][k]]);
sort(all(v));
reverse(all(v));
int w=0;
rep(k,C[j]){
if(w-k<v[k]){
w=k+v[k];
}
}
chmin(F[G[j]],w);
}
}
T--;
if(F[T]==1001001001)cout<<-1<<endl;
else cout<<F[T]<<endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment