Cod sursa(job #3263576)

Utilizator Andrei1209Andrei Mircea Andrei1209 Data 15 decembrie 2024 10:47:21
Problema Dusman Scor 50
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.09 kb
#include <fstream>

using namespace std;
ifstream fin("dusman.in");
ofstream fout("dusman.out");
bool a[1005][1005];
int n, k, m, st[1005], cnt, folosit[1005];
bool verif(int poz )
{
    if ( a[st[poz]][st[poz - 1]] == 1 )
        return false;
    for ( int i = 1; i < poz; ++i )
        if ( st[i] == st[poz] )
            return false;
    return true;
}
void Back( int poz )
{
    if (poz == n + 1)
    {
        ++cnt;
        if ( cnt == k )
        {
            for ( int i = 1; i <= n; ++i )
                fout << st[i] << " ";

        }

    }
    else if ( cnt < k )
    {
        int i;
        for ( i = 1; i <= n; ++i )
        {
            st[poz] = i;
            if ( folosit[i] == 0 && a[st[poz]][st[poz - 1]] == 0 )
            {
                folosit[i] = 1;
                Back(poz + 1);
                folosit[i] = 0;
            }
        }
    }
}
int main()
{
    fin >> n >> k >> m;
    int i, x, y;
    for ( i = 1; i <= n; ++i )
    {
        fin >> x >> y;
        a[x][y] = a[y][x] = 1;
    }
    Back(1);
    return 0;
}