fork download
  1. #include <iostream>
  2. #include <vector>
  3. using namespace std;
  4.  
  5. const int X = 250000;
  6. vector<int> galezie[X];
  7. bool visited[X];
  8. int blue = 0, red = 0;
  9. void jaki_kolor(int a, int kolor){
  10. visited[a] = true;
  11. if (kolor == 0) blue++;
  12. else red++;
  13. for (int nastepny : galezie[a]){
  14. if (visited[nastepny]==false){
  15. jaki_kolor(nastepny, 1 - kolor);
  16. }
  17. }
  18. }
  19. int main() {
  20. ios::sync_with_stdio(false);
  21. cin.tie(0);
  22. int n;
  23. cin >> n;
  24. for (int i = 1; i < n; ++i) {
  25. int a, b;
  26. cin >> a >> b;
  27. galezie[a].push_back(b);
  28. galezie[b].push_back(a);
  29. }
  30. jaki_kolor(1, 0);
  31. cout << blue << " " << red << '\n';
  32. return 0;
  33. }
Success #stdin #stdout 0.01s 9420KB
stdin
10
5 10
8 9
2 10
4 10
5 6
9 7
10 1
7 10
7 3
stdout
6 4