Pagini recente » Cod sursa (job #368978) | Cod sursa (job #1414478) | Cod sursa (job #2257362) | Cod sursa (job #1910178) | Cod sursa (job #446177)
Cod sursa(job #446177)
#include <stdio.h>
char a[10001][10001];
int st[1001];
int n, m, K;
int i, j, k;
int AS, nr;
int Am_Succesor ()
{
if (st[k] < n)
{
st[k] ++;
return 1;
}
return 0;
}
int E_Valid ()
{
int z;
for (z=1; z<k; ++z)
if (st[k] == st[z] || a[st[k]][st[k-1]] == 1)
return 0;
return 1;
}
int main ()
{
FILE *f = fopen ("dusman.in","r");
FILE *g = fopen ("dusman.out","w");
fscanf (f,"%d %d %d", &n, &K, &m);
for (k=1; k<=m; ++k)
{
fscanf (f,"%d %d", &i, &j);
a[i][j] = a[j][i] = 1;
}
fclose(f);
k = 1;
st[k] = 0;
while (k > 0 && nr <= K)
{
//do
//{ }
while ( (AS = Am_Succesor ()) && !E_Valid());
if (AS)
{
if (k == n)
{
nr ++;
if (nr == K)
{
for (i=1; i<=k; ++i)
fprintf (g,"%d ", st[i]);
fprintf (g,"\n");
break;
}
}
else
{
k ++;
st[k] = 0;
}
}
else
k --;
}
return 0;
}