Pagini recente » Cod sursa (job #576767) | Cod sursa (job #3208698) | Cod sursa (job #444372) | Cod sursa (job #335897) | Cod sursa (job #252833)
Cod sursa(job #252833)
#include<fstream.h>
int v[1002][3],z=0,n,k,m,i,s[1003],a,b,q,ok;
int main()
{
ifstream f("dusman.in");
ofstream g("dusman.out");
f>>n>>k>>m;
for(i=0;i<m;i++)
f>>v[i][0]>>v[i][1];
q=0;
s[q]=0;
while(q>=0)
if(s[q]<n)
{
s[q]++;
ok=1;
for(i=0;i<q;i++)
if(s[i]==s[q])ok=0;
for(i=0;i<m;i++)
if(s[q-1]==v[i][0]&&s[q]==v[i][1]||s[q-1]==v[i][1]&&s[q]==v[i][0])ok=0;
if(ok)
if(q==n-1)
{
z++;
if(z==k)
{for(i=0;i<n;i++)g<<s[i]<<" ";break;}
}
else {q++;s[q]=0;}
}
else q--;
return 0;
}