Pagini recente » Cod sursa (job #1405370) | Cod sursa (job #456096) | Cod sursa (job #1042303) | Cod sursa (job #1136210) | Cod sursa (job #446191)
Cod sursa(job #446191)
#include <fstream>
std::ifstream in("dusman.in");
std::ofstream out("dusman.out");
int n,poz,m;
int d[1002][1002],sir[1002];
bool fol[1002];
void afisare()
{
int i;
for(i=0;i<n;i++)
out<<sir[i]<<" ";
out<<'\n';
}
void back(int k)
{
int i,j;
if(k==n&&poz>0)
if(poz==1)
afisare(),poz--;
else
poz--;
else
if(poz>0)
for(i=1;i<=n;i++)
{
if(fol[i]==0&&d[i][sir[k-1]]==0)
{
sir[k]=i;
fol[i]=1;
back(k+1);
fol[i]=0;
}
}
}
int main ()
{
int i,nr,x;
in>>n>>poz>>m;
for(i=0;i<m;i++)
{
in>>nr>>x;
d[nr][x]=1;
d[x][nr]=1;
}
back(0);
return 0;
}