Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int a[100][100], n, m;
- int viz[100], queue[100], v[100], pr, ul, este_complet;
- //Parcurgerile esentiale
- void BFS(int nod) {
- int x;
- viz[nod] = 1;
- pr = 0;
- ul = -1;
- queue[++ul] = nod;
- while (pr <= ul) {
- for (int i = 1; i <= n; i++) {
- x = queue[ul];
- if (a[x][i] == 1 && viz[i] == 0) {
- queue[++ul] = i;
- if (viz[x] == 1) viz[i] = 2;
- else viz[i] = 1;
- }
- }
- pr++;
- }
- }
- void DFS(int nod) {
- v[nod] = 1;
- for (int i = 1; i <= n; i++)
- if (v[i] == 0 && a[nod][i] == 1)
- DFS(i);
- }
- //Functii extra
- void Vizitare() {
- for (int i = 1; i <= n; i++)
- v[i] = 0;
- }
- int Bipartit() {
- for (int i = 1; i < n; i++)
- for (int j = i + 1; j <= n; j++)
- if (viz[i] == viz[j])
- if (a[i][j] == 1)
- return 0;
- return 1;
- }
- void verificareBipartit()
- {
- if (Bipartit() == 1)
- cout << "Bipartit";
- else cout << "NU";
- }
- int Conex(int v[]) {
- for (int i = 1; i <= n; i++)
- if (v[i] != 1) return 0;
- return 1;
- }
- void verificareConex(int v[])
- {
- if (Conex(v) == 1)
- cout << "Graf conex";
- else
- cout << "Nu este conex";
- }
- int existaNodNev() {
- for (int i = 1; i <= n; i++)
- if (viz[i] == 0)
- return i;
- return 0;
- }
- void complet()
- {
- for (int i = 1; i <= n; i++) {
- for (int j = 1; j <= n; j++) {
- if (a[i][j] == 0 && i != j) {
- este_complet = 0;
- break;
- }
- }
- if (este_complet == 0) {
- break;
- }
- }
- if (este_complet == 1) {
- cout << "Graful este complet. ";
- }
- else {
- cout << "Graful este incomplet. ";
- }
- }
- int main() {
- int x, y;
- cout << "Scrie numarul de varfuri: ";
- cin >> n;
- cout << "Scrie numarul de muchii: ";
- cin >> m;
- for (int i = 1; i <= m; i++) {
- cout << "Scrie extremitatile muchiei " << i << ": ";
- cin >> x >> y;
- a[x][y] = 1;
- a[y][x] = 1;
- }
- complet();
- }
- /*
- exemplu graf bipartit
- 7
- 7
- 1 2
- 1 3
- 1 5
- 2 4
- 3 7
- 4 6
- 6 7
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement