Advertisement
Guest User

Untitled

a guest
Mar 19th, 2015
327
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.34 KB | None | 0 0
  1. /*
  2. */
  3.  
  4. //#pragma comment(linker, "/STACK:16777216")
  5. #include <fstream>
  6. #include <iostream>
  7. #include <string>
  8. #include <complex>
  9. #include <math.h>
  10. #include <set>
  11. #include <vector>
  12. #include <map>
  13. #include <queue>
  14. #include <stdio.h>
  15. #include <stack>
  16. #include <algorithm>
  17. #include <list>
  18. #include <ctime>
  19. #include <memory.h>
  20. #include <ctime>
  21.  
  22. #define y0 sdkfaslhagaklsldk
  23. #define y1 aasdfasdfasdf
  24. #define yn askfhwqriuperikldjk
  25. #define j1 assdgsdgasghsf
  26. #define tm sdfjahlfasfh
  27. #define lr asgasgash
  28.  
  29. #define eps 1e-9
  30. //#define M_PI 3.141592653589793
  31. #define bs 1000000007
  32. #define bsize 256
  33. #define right adsgasgadsg
  34. #define free adsgasdg
  35. #define MAGIC 47
  36. #define count adsgasdgasdg
  37.  
  38. using namespace std;
  39.  
  40. int n,m,a,b;
  41. bool ar[10050][10050];
  42. int used[10050];
  43. int visited;
  44.  
  45. void dfs(int v)
  46. {
  47. used[v]=1;
  48. visited++;
  49. for (int i=1;i<=n;i++)
  50. if (ar[v][i]==1&&used[i]==0)
  51. dfs(i);
  52. }
  53.  
  54. int main(){
  55. //freopen("k.in","r",stdin);
  56. //freopen("k.out","w",stdout);
  57. //freopen("C:/input.txt","r",stdin);
  58. //freopen("C:/output.txt","w",stdout);
  59. ios_base::sync_with_stdio(0);
  60. //cin.tie(0);
  61.  
  62. cin>>n>>m;
  63. for (int i=0;i<m;i++)
  64. {
  65. cin>>a>>b;
  66. ar[a][b]=ar[b][a]=1;
  67. }
  68. if (m!=n-1)
  69. {
  70. cout<<"NO"<<endl;
  71. return 0;
  72. }
  73.  
  74. dfs(1);
  75. if (visited!=n)
  76. cout<<"NO"<<endl;
  77. else cout<<"YES"<<endl;
  78.  
  79. cin.get();cin.get();
  80. return 0;}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement