Pagini recente » Cod sursa (job #2173840) | Diferente pentru info-oltenia-2018/individual/clasament/11-12 intre reviziile 2 si 4 | Cod sursa (job #2199746) | Atasamentele paginii 777momento | Cod sursa (job #2369985)
#include <fstream>
using namespace std;
ifstream fin("date.in");
ofstream fout("date.out");
int a[30][30],n,s[20][20],c[20][20],nc,L[20],p[20][20];
void citire()
{
fin>>n;
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
fin >> a[i][j];
fout<<'\n';
}
void afisare()
{
for(int i=1;i<=n;i++)
{
for(int j=1;j<=n;j++)
fout<<a[i][j]<<' ';
fout<<'\n';
}
fout<<'\n';
}
void generare()
{
for(int k=1;k<=n;k++)
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
if(!a[i][j] && i!=k && j!=k)
a[i][j]=a[i][k]*a[k][j];
}
void det_s(int i,int &nr)
{
int j=0,k;
for(k=1;k<=n;k++)
if(a[i][k]==1)
{
s[i][j]=1;
j++;
}
nr=j++;
}
void det_p(int i,int &nr)
{
int k,j=0;
for(k=1;k<=n;k++)
if(a[k][i]==1)
{
p[i][j]=1;
j++;
}
nr=j++;
}
int cautare(int A[20],int x, int m)
{
int j0,gasit=0;
for(j0=1;j0<=m;j0++)
if(A[j0]==x)
gasit=1;
return gasit;
}
void intersectie(int A[20], int B[20], int C[20], int m1, int m2, int &nr)
{
int j1,j2,j0;
for(j0=1;j0<=m1;j0++)
{
j2=0;
for(j1=1;j1<=m2;j1++)
if(A[j0]==B[j1])
{
C[j2]=A[j0];
j2++;
}
nr=j2;
}
}
void tare_conex()
{
int i,j,ks,kp,k,i0;
j=0;k=0;
nc=0;
for(i=1;i<=n;i++)
if(!cautare(L,i,j))
{
nc++;
det_s(i,ks);
det_p(i,kp);
intersectie(s[i],p[i],c[i],ks,kp,k);
for(int i0=1;i0<=k;i0++)
{
L[j]=c[i][i0];
j++;
}
fout<<"\n Componenta "<< nc <<" este ";
for(i0=1;i0<=n;i0++)
if(cautare(c[i],i0,k))
fout<<i0<<' ';
fout<<'\n';
}
}
int main()
{
citire();
afisare();
generare();
afisare();
tare_conex();
fin.close();
fout.close();
}