#include<bits/stdc++.h> #define FOR(i,s,e) for(int i=(s);i<=(e);i++) #define FORD(i,s,e) for(int i=(s);i>=(e);i--) #define ALL(k) (k).begin(),(k).end() #define e1 first #define e2 second #define MP make_pair #define PB push_back #define EB emplace_back using namespace std; typedef long long LL; typedef pair<int,int> PII; typedef pair<LL,LL> PLL; typedef pair<int,PII> PIP; typedef pair<PLL,PLL> PPP; const int MAXN=211; int odw[3][MAXN]; char aa[MAXN]; PII kraw[MAXN*MAXN]; main(){ int n,b,r;scanf("%d%d%d",&n,&b,&r); int ilkr=0; FOR(i,1,n){ scanf("%s",aa+1); FOR(j,1,n){ if(aa[j]=='1'){ ilkr++; kraw[ilkr]={i,j}; } } } FOR(i,1,r){ int a;scanf("%d",&a); odw[0][a]=1; } int i1=0,i2=1; int MAXW=((int)4e8)/(ilkr+n); FOR(kk,1,MAXW){ swap(i1,i2); FOR(i,1,n) odw[i1][i]=0; FOR(i,1,ilkr){ if(odw[i2][kraw[i].e1]) odw[i1][kraw[i].e2]=1; } int ok=1; FOR(i,b+1,n) if(odw[i1][i]) {ok=0;break;} if(ok==1) {printf("%d\n",kk);return 0;} } puts("-1"); }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 | #include<bits/stdc++.h> #define FOR(i,s,e) for(int i=(s);i<=(e);i++) #define FORD(i,s,e) for(int i=(s);i>=(e);i--) #define ALL(k) (k).begin(),(k).end() #define e1 first #define e2 second #define MP make_pair #define PB push_back #define EB emplace_back using namespace std; typedef long long LL; typedef pair<int,int> PII; typedef pair<LL,LL> PLL; typedef pair<int,PII> PIP; typedef pair<PLL,PLL> PPP; const int MAXN=211; int odw[3][MAXN]; char aa[MAXN]; PII kraw[MAXN*MAXN]; main(){ int n,b,r;scanf("%d%d%d",&n,&b,&r); int ilkr=0; FOR(i,1,n){ scanf("%s",aa+1); FOR(j,1,n){ if(aa[j]=='1'){ ilkr++; kraw[ilkr]={i,j}; } } } FOR(i,1,r){ int a;scanf("%d",&a); odw[0][a]=1; } int i1=0,i2=1; int MAXW=((int)4e8)/(ilkr+n); FOR(kk,1,MAXW){ swap(i1,i2); FOR(i,1,n) odw[i1][i]=0; FOR(i,1,ilkr){ if(odw[i2][kraw[i].e1]) odw[i1][kraw[i].e2]=1; } int ok=1; FOR(i,b+1,n) if(odw[i1][i]) {ok=0;break;} if(ok==1) {printf("%d\n",kk);return 0;} } puts("-1"); } |