Pagini recente » Cod sursa (job #1380090) | Cod sursa (job #1920974) | Cod sursa (job #458906) | Cod sursa (job #3269239) | Cod sursa (job #446189)
Cod sursa(job #446189)
#include <fstream>
std::ifstream in("dusman.in");
std::ofstream out("dusman.out");
int perm,n,d1[1000],d2[1000],p,x[1000];
bool fol[1200];
void scrie()
{
int i;
for(i=1;i<=n;i++)
out<<x[i]<<" ";
out<<'\n';
}
bool verifica(int k)
{
int i,j;
/*for(i=0;i<p;i++)
{
if(d1[i]==x[k]||d2[i]==x[k])
{
if(d1[i]==x[k-1]||d2[i]==x[k-1])
return false;
}
}
*/
if(fol[k]==true)
return false;
return true;
}
void back()
{
int k=1;
x[k]=0;
do
{
//out<<k<<'\n';
if(x[k]<n)
{
x[k]++;
if(verifica(k))
{
fol[x[k]]=true;
fol[x[k-1]]=false;
if(k==n)
{
scrie();
/*if(perm==1)
{
scrie();
return ;
}
else
perm--;
*/
}
else
{
k++;
x[k]=0;
}
}
}
else
{ fol[x[k]]=false;
k--;
}
}
while(k>0&&perm>0);
}
int main ()
{
int i,r;
in>>n>>perm>>p;
for(i=0;i<p;i++)
in>>d1[i]>>d2[i];
back();
//scrie();
return 0;
}