Created
April 24, 2016 00:21
-
-
Save jianminchen/1858f0b4994efc65c99701290fb951ec to your computer and use it in GitHub Desktop.
Even Try - HackerRank - Graph problem - study code - very short, figure out the design
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
namespace Solution | |
{ | |
class Solution | |
{ | |
static void Main(string[] args) | |
{ | |
var line1 = Console.ReadLine().Trim().Split(' '); | |
var vTotal = int.Parse(line1[0]); | |
var eTotal = int.Parse(line1[1]); | |
int[] vPoint = new int[vTotal]; | |
int[] vParent = new int[vTotal]; | |
for (int i = 0; i < eTotal; i++) | |
{ | |
var line = Console.ReadLine().Trim().Split(' '); | |
int vPo = int.Parse(line[0]); | |
int vPa = int.Parse(line[1]); | |
vPoint[vPo - 1] = 1; | |
vParent[vPo - 1] = vPa; | |
while (vPa != 1) | |
{ | |
vPoint[vPa - 1]++; | |
vPa = vParent[vPa - 1]; | |
} | |
} | |
int m = 0; | |
for (int i = 1; i < vPoint.Length; i++) | |
{ | |
if (vPoint[i] % 2 == 0) | |
m++; | |
} | |
Console.WriteLine(m); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment