Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <queue>
- #include <random>
- #define mp make_pair
- #define cve(tpy) for (int i = 0; i < sizeof(tpy)/sizeof(tpy[0]); i++) {for(int j = 0; j < sizeof(tpy[i])/sizeof(tpy[i][0]); j++){cout << tpy[i][j] << " "; }cout << "\n";} ;
- #define f first
- #define s second
- #define loop(i, x, n) for (int i = x; i < n; i++)
- #define joop(x, n) for (ll j = x; j < n; j++)
- #define lp(n) for (ll i = 0; i < n; i++)
- #define err cout << "ERROR" << endl;
- #define all(x) x.begin(), x.end()
- #define pb push_back
- #define sz(x) x.size()
- #define rndm rng()
- using namespace std;
- // types
- typedef long long ll;
- typedef long double ld;
- // types of data
- #define inf 1000000000
- #define infll 1000000000000000000
- #define INF ll(1e9)
- #define md 998244353
- #define mod 1000000009
- //#define K 239017
- #define DEBUG 1
- const int N = 20;
- void bfs(int adjList[N][N], int startNode, bool visited[N]) {
- // Create a queue for BFS
- int queue[N];
- int front = 0, rear = 0;
- // Mark the current node as visited and enqueue it
- visited[startNode] = true;
- queue[rear++] = startNode;
- // Iterate over the queue
- while (front != rear) {
- int currentNode = queue[front++];
- for (int neighbor = 0; neighbor < N; neighbor++) {
- if (adjList[currentNode][neighbor] && !visited[neighbor]) {
- visited[neighbor] = true;
- queue[rear++] = neighbor;
- }
- }
- }
- }
- void solve() {
- int n = 20;
- int g[N][N] = {0};
- loop(i, 0, n) {
- loop(j, 0, n) {
- int a;
- cin >> a;
- if (a == 1) {
- g[i][j] = 1;
- g[j][i] = 1;
- }
- }
- }
- int start = 2;
- bool vis[N] = {0};
- cout << "first group:\n";
- bfs(g, start, vis);
- loop(i, 0, n) {
- if (vis[i]) {
- cout << i + 1 << " ";
- }
- }
- cout << "\n";
- cout << "second group:\n";
- bool vis2[N] = {0};
- bfs(g, start, vis2);
- loop(i, 0, n) {
- if (!vis2[i]) {
- cout << i + 1 << " ";
- }
- }
- }
- int main() {
- freopen("text.txt", "r", stdin);
- solve();
- return 1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement