Advertisement
Guest User

Untitled

a guest
Jan 22nd, 2017
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.28 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. using namespace std;
  4.  
  5. #define N 100001
  6.  
  7. bool odw[N];
  8. vector <int> G[N];
  9. int ile[N];
  10.  
  11. int main()
  12. {
  13. ios_base::sync_with_stdio(false);
  14. int c;
  15. cin >> c;
  16. for(int k = 0 ; k < c ; k++)
  17. {
  18. int n, m;
  19. cin >> n >> m;
  20.  
  21. for(int i = 0 ; i < m ; i++)
  22. {
  23. int a, b;
  24. cin >> a >> b;
  25. ile[a]++;
  26. ile[b]++;
  27. G[a].push_back(b);
  28. G[b].push_back(a);
  29. }
  30. bool czy = true;
  31. int n1 = n;
  32. while(czy)
  33. {
  34. czy = false;
  35. for(int i = 1 ; i <= n ; i++)
  36. {
  37. if(odw[i] == false)
  38. {
  39. if(ile[i] < 2)
  40. {
  41. if(G[i].size() != 0)
  42. ile[G[i][0]]--;
  43. n1--;
  44. odw[i] = true;
  45. czy = true;
  46. }
  47. }
  48. }
  49. }
  50. if(n1 == 0)
  51. cout << "NIE\n";
  52. else
  53. cout << "TAK\n";
  54.  
  55. for(int i = 1 ; i <= n ; i++)
  56. {
  57. G[i].clear();
  58. ile[i] = 0;
  59. odw[i] = false;
  60. }
  61. }
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement