fork download
  1. from sys import setrecursionlimit
  2. setrecursionlimit(10**7)
  3. #Class for graph
  4. class MYGraph:
  5. def __init__(self,V):
  6. self.graph=[[] for i in range(V)]
  7. self.visited=[False for i in range(V)]
  8.  
  9. def addEdges(self,No):
  10. for _ in range(No):
  11. u,v=map(int, input().split())
  12. self.graph[u-1].append(v-1)
  13. self.graph[v-1].append(u-1)
  14.  
  15. def DFS(self,visit,cnt):
  16. self.visited[visit]=True
  17. cnt+=1
  18. for i in self.graph[visit]:
  19. if not self.visited[i]:
  20. cnt=self.DFS(i,cnt)
  21. return cnt
  22.  
  23. #Taking Input
  24. N, E = map(int, input().split())
  25. g = MYGraph(N)
  26. g.addEdges(E)
  27. kill_the_Code = 0
  28. single = 0
  29. programer_arr = 0
  30.  
  31. #count both
  32. for i in range(N):
  33. if not g.visited[i]:
  34. cnt=g.DFS(i, 0)
  35. if cnt == 1:
  36. single+=1
  37. else:
  38. programer_arr+=cnt//5
  39. if cnt%5:
  40. programer_arr+=1
  41. kill_the_Code+=1
  42.  
  43. #if single Atom
  44. programer_arr+=single
  45. print(kill_the_Code,programer_arr)
  46.  
Success #stdin #stdout 0.02s 9300KB
stdin
6 7
1 2
1 6
1 5
2 3
6 3
6 4
5 4
stdout
1 2