Pagini recente » Cod sursa (job #2558005) | Cod sursa (job #2206816) | Cod sursa (job #1818901) | Cod sursa (job #3162858) | Cod sursa (job #519499)
Cod sursa(job #519499)
#include <iostream>
#include <fstream>
using namespace std;
int coridor[256][256],*lumini,n,contor;
int trecutx=1,trecuty=1,ajuns,*bifa,last=1,last2=1;
void read()
{
int x,y;
ifstream in("trigame.in");
in>>n;
for(int i=1;i<=n;i++)
{in>>x>>y; coridor[x][y]=coridor[y][x]=1;}
in.close();
/*for(int k=1;k<=n;k++){cout<<endl;
for(int j=1;j<=n;j++)
cout<<[k][j]<<" ";}*/
}
void reinit()
{
delete [] bifa;
bifa=new int[n+1];
//cout<<bifa;
trecutx=1;
trecuty=1;
for(int i=1;i<=n;i++)
{bifa[i]=0;}
last=1;
last2=1;
}
void rezolva()
{ int l,x,y,poz_il[256],poz_fat[256];
bifa=new int[256];
for(int i=1;i<=n;i++)
{bifa[i]=0;}
int i,j,k; //Ileana,varf,fat-frumos
for(i=1;i<=n;i++) //Fiecare pozitie IL
for(k=1;k<=n;k++) //Fiecare pozitie Fat
{ if(k!=i)
{ //cout<<k<<" "<<i<<endl;
ajuns=1;
poz_il[1]=i;
poz_fat[1]=k;
bifa[i]=bifa[k]=1;
last=1;
last2=1;
trecutx=1;
trecuty=1;
while(ajuns){ajuns=0;
l=last;
for(x=1;x<=n;x++)
if(coridor[x][poz_il[trecutx]]==1&&bifa[x]==0)
{
poz_il[++last]=x;
bifa[x]=1;
//cout<<poz_il[last]<<" ";
}
int l2;
l2=last2;
for(y=1;y<=n;y++)
if(coridor[y][poz_fat[trecuty]]==1&&bifa[y]==0)
{ poz_fat[++last2]=y;
bifa[y]=1;
ajuns=1;
}
//cout<<l<<" "<<last<<endl;
// cout<<last<<" "<<trecutx<<endl;
if(l2==last2&&l<last)
{// cout<<i<<" "<<k<<endl;
contor++;}
trecutx++;
trecuty++;
}
reinit();
}}
}
int main()
{
read();
rezolva();
ofstream out("trigame.out");
out<<contor;
//cout<<endl<<endl<<contor;
out.close();
return 0;
}