Skip to content

Instantly share code, notes, and snippets.

@jianminchen
Created April 24, 2016 00:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jianminchen/1858f0b4994efc65c99701290fb951ec to your computer and use it in GitHub Desktop.
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
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