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