-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path2c.cpp
48 lines (42 loc) · 975 Bytes
/
2c.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include <iostream>
using namespace std;
int n,m,mat[101][101],x,y;
int coada[201],inc=0,sf=0;
bool v[101]; /// vector de frecventa
int main()
{
/// Citire
cin >> n >> m;
for(int i=1;i<=m;i++)
{
cin >> x >> y;
/// trecem in matrice
mat[x][0]++;
mat[x][mat[x][0]] = y;
mat[y][0]++;
mat[y][mat[y][0]] = x;
}
coada[sf++] = 1;
v[1] = 1;
while(inc < sf)
{
for(int i=1;i<=mat[coada[inc]][0];i++)
if(!v[mat[coada[inc]][i]])
{
coada[sf++] = mat[coada[inc]][i];
v[mat[coada[inc]][i]] = 1;
}
// for(int i=inc;i<sf;i++)
// cout << coada[i] << " ";
// cout << endl;
inc++;
}
for(int i=1;i<=n;i++)
if(!v[i])
{
cout << "Nu e conex!";
return 0;
}
cout << "E conex!";
return 0;
}