fork(1) download
  1. #include <stdio.h>
  2. #include <algorithm>
  3. #include <vector>
  4.  
  5. using namespace std;
  6.  
  7. const int MAXN = 1e3 + 5;
  8.  
  9. vector<int> adj[MAXN];
  10. int N, M, vis[MAXN], sz;
  11.  
  12. int dfs(int u){
  13. vis[u] = 1, sz++;
  14. int c = 0;
  15. for(auto it : adj[u]){
  16. c++;
  17. if(!vis[it]) c += dfs(it);
  18. }
  19. return c;
  20. }
  21.  
  22. int main(){
  23. #ifdef DEBUG
  24. freopen("input.txt", "r", stdin);
  25. #endif
  26. scanf("%d %d", &N, &M);
  27. while(M--){
  28. int x, y;
  29. scanf("%d %d", &x, &y);
  30. adj[x].push_back(y);
  31. adj[y].push_back(x);
  32. }
  33. int cnt = 0, complete = 0;
  34. for(int i=1; i<=N; ++i){
  35. if(!vis[i]){
  36. cnt++, sz = 0;
  37. int x = dfs(i);
  38. if(x / 2 == sz * (sz - 1) / 2) complete++;
  39. }
  40. }
  41. if((complete == 1 && cnt == 1) || (complete == 2 && cnt == 2)) puts("DA");
  42. else puts("NE");
  43. return 0;
  44. }
Success #stdin #stdout 0s 3488KB
stdin
Standard input is empty
stdout
NE