Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <fstream>
- #include <vector>
- using namespace std;
- ifstream cin("conex.in");
- ofstream cout("conex.out");
- const int DIM = 101;
- int a[DIM][DIM], q[DIM], viz[DIM], t[DIM];
- void bfs(int x, int nc);
- int n;
- int main()
- {
- int m, k;
- cin >> n;
- int x, y;
- while(cin >> x >> y)
- {
- a[x][y] = a[y][x] = 1;
- }
- int conex = 0;
- bfs(1, conex + 1);
- return 0;
- }
- void bfs(int k, int nc)
- {
- int st, dr, nod;
- st = dr = 0;
- q[st] = k;
- viz[k] = nc;
- while(st <= dr)
- {
- nod = q[st++];
- for(int i = 1; i <= n; ++i)
- {
- if(a[nod][i])
- {
- if(!viz[i])
- {
- q[++dr] = i;
- viz[i] = nc;
- t[i] = nod;
- }
- }
- }
- }
- if(n == dr + 1)
- cout << "DA";
- else
- cout << "NU";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement