Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //COLORAREA HARTILOR
- #include <iostream>
- #include <fstream>
- #include <math.h>
- using namespace std;
- ifstream fin("adiacenta1.txt");
- int A[50][50], st[50], n;
- void Citire(int &n)
- {
- int i, j;
- fin >> n;
- while (fin >> i >> j)
- {
- A[i][j] = A[j][i] = 1;
- }
- fin.close();
- }
- int Solutie(int k)
- {
- return n == k;
- }
- void Tipar()
- {
- for (int i = 1; i <= n; i++)
- cout << st[i] << " ";
- cout << "\n";
- }
- int Valid(int k)
- {
- for (int i = 1; i < k; i++)
- if (st[i] == st[k] && A[i][k]==1 )
- return 0;
- return 1;
- }
- void bkt(int k)
- {
- for (int i = 1; i <= 4; i++)
- {
- st[k] = i;
- if (Valid(k))
- {
- if (Solutie(k))
- Tipar();
- else
- bkt(k + 1);
- }
- }
- }
- int main()
- {
- Citire(n);
- bkt(1);
- cout << "\n";
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement