Advertisement
myname0

graph_contester_8

May 22nd, 2016
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.54 KB | None | 0 0
  1. public class Graph
  2.     {
  3.         private class Node
  4.         {
  5.             List<List<int>> array = new List<List<int>>();
  6.  
  7.             public Node(List<List<int>> tmp)
  8.             {
  9.                 array = tmp;
  10.             }
  11.  
  12.             public int CountEvenVertex()
  13.             {
  14.                 int count = 0;
  15.                 foreach (var item in array)
  16.                     if (item.Count % 2 == 0)
  17.                         count++;
  18.                 return count;
  19.             }
  20.  
  21.         }
  22.         private Node graph;
  23.  
  24.         public Graph(string nameOfFile)
  25.         {
  26.             StreamReader fin = new StreamReader(nameOfFile);
  27.             int n = int.Parse(fin.ReadLine());
  28.             List<List<int>> tmp = new List<List<int>>();
  29.             for (int i = 0; i < n; i++)
  30.             {
  31.                 List<int> tmp2 = new List<int>();
  32.                 string[] arr = fin.ReadLine().Split(' ');
  33.                 for (int j = 1; j < arr.Length; j++)
  34.                     tmp2.Add(int.Parse(arr[j]) - 1);
  35.                 tmp.Add(tmp2);
  36.             }
  37.             fin.Close();
  38.             graph = new Node(tmp);
  39.         }
  40.  
  41.         public int CountEvenVertex()
  42.         {
  43.             return graph.CountEvenVertex();
  44.         }      
  45.     }
  46.     class Program
  47.     {
  48.         static void Main(string[] args)
  49.         {
  50.             Graph graph1 = new Graph("input.txt");
  51.             StreamWriter fout = new StreamWriter("output.txt");
  52.             fout.WriteLine("{0}", graph1.CountEvenVertex());
  53.             fout.Close();
  54.         }
  55.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement