Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int main()
- {
- int n, k, tmp;
- fin >> n;
- int** adjacency_list = new int*[n];
- int *col = new int[n];
- for (auto i = 0; i < n; i++) {
- fin >> k;
- col[i] = -1;
- adjacency_list[i] = new int[k + 1];
- adjacency_list[i][0] = k;
- for (auto j = 1; j <= k; j++)
- {
- fin >> tmp;
- adjacency_list[i][j] = tmp;
- }
- }
- print(adjacency_list, n);
- col[0] = 1;
- for (auto i = 0; i < n; ++i) {
- if (col[i] != -1) {
- for (auto j = 1; j <= adjacency_list[i][0]; ++j)
- {
- if (col[adjacency_list[i][j] - 1] == -1) {
- switch (col[i]) {
- case 0:
- col[adjacency_list[i][j] - 1] = 1;
- break;
- case 1:
- col[adjacency_list[i][j] - 1] = 0;
- break;
- default:
- break;
- }
- }
- }
- }
- else {
- for (auto j = 1; j <= adjacency_list[i][0]; ++j)
- {
- if (col[adjacency_list[i][j] - 1] == 1)
- {
- col[i] = 0;
- }
- else if (col[adjacency_list[i][j] - 1] == 0)
- {
- col[i] = 1;
- }
- }
- }
- }
- for (auto i = 0; i < n; ++i) {
- cout << col[i] << " ";
- }
- fout << min(count(col, col + n, 0), count(col, col + n, 1));
- cout << endl << min(count(col, col + n, 0), count(col, col + n, 1));
- fin.close();
- fout.close();
- delete[] col;
- for (auto i = 0; i < n; i++) {
- delete[] adjacency_list[i];
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement