Advertisement
Guest User

Untitled

a guest
Oct 25th, 2012
492
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.93 KB | None | 0 0
  1.  
  2. import java.util.Scanner;
  3. import java.util.Arrays;
  4.  
  5. public class Solution {
  6.  
  7. /**
  8. * @param args
  9. */
  10.  
  11. public static void main(String[] args) {
  12. // TODO Auto-generated method stub
  13.  
  14. int tree[];
  15. int count[];
  16.  
  17. Scanner scan = new Scanner(System.in);
  18.  
  19. int N = scan.nextInt(); //points
  20. int M = scan.nextInt();
  21.  
  22. tree = new int[N];
  23. count = new int[N];
  24. Arrays.fill(count, 1);
  25.  
  26. for(int i=0;i<M;i++)
  27. {
  28. int u1 = scan.nextInt();
  29. int v1 = scan.nextInt();
  30.  
  31. tree[u1-1] = v1;
  32.  
  33. count[v1-1] += count[u1-1];
  34.  
  35. int root = tree[v1-1];
  36.  
  37. while(root!=0)
  38. {
  39. count[root-1] += count[u1-1];
  40. root = tree[root-1];
  41. }
  42. }
  43.  
  44. System.out.println("");
  45.  
  46. int counter = -1;
  47. for(int i=0;i<count.length;i++)
  48. {
  49. if(count[i]%2==0)
  50. {
  51. counter++;
  52. }
  53.  
  54. }
  55. System.out.println(counter);
  56.  
  57. }
  58.  
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement