using System; using System.Collections.Generic; namespace ConsoleApp2 { class Program { static int readint() { return Convert.ToInt32(Console.ReadLine()); } static void swap(ref string a, ref string b) { string temp = a; a = b; b = temp; } struct vec2d { public int x, y; public void neguj() { x = -x; y = -y; } public double delka() { return Math.Sqrt(x * x + y * y); } }; class IntReader { public IntReader() { fill(); } private Queue queue = new Queue(); public bool Eof() { return queue.Count == 0; } public int Read() { int i = queue.Dequeue(); if (queue.Count == 0) fill(); return i; } void fill() { while (queue.Count == 0) { string s = Console.ReadLine(); if (s == null) break; String[] ss = s.Split(); foreach (string snum in ss) { int i; if (Int32.TryParse(snum, out i)) queue.Enqueue(i); } } } }; static void Main4(string[] args) { IntReader ir = new IntReader(); while (! ir.Eof()) { Console.WriteLine(ir.Read()); } /* List a; a = new List(); for(;;) { int x = readint(); if (x == 0) break; a.Add(x); } int count = a.Count; for (int i = 0; i < count; i++) { Console.WriteLine(a[count - i - 1]); } */ } static void Main3(string[] args) { vec2d a; a.x = 5; a.y = 1; vec2d b; b = a; Console.WriteLine("{0}, {1}", b.x, b.y); b.neguj(); Console.WriteLine("{0}, {1}", b.x, b.y); Console.WriteLine(b.delka()); } static void Main(string[] args) { /* string[] a = new string[10]; for (int i = 0; i < 10; i++) { a[i] = Console.ReadLine(); } for (int i = 0; i < 10; i++) { for (int e = 0; e < 9; e++) if(a[e].CompareTo(a[e+1]) > 0) swap(ref a[e], ref a[e + 1]); } for (int i = 0; i < 10; i++) { Console.WriteLine(a[i]); } */ int count, i, j; IntReader ir = new IntReader(); count = ir.Read(); int[,] dist = new int[count, count]; for (i = 0; i < count; i++) for (j = 0; j < count; j++) dist[i, j] = (i == j) ? 0 : 9999; while (true) { int od, kam, vzdalenost; od = ir.Read(); if (od < 0) break; kam = ir.Read(); vzdalenost = ir.Read(); dist[od, kam] = vzdalenost; dist[kam, od] = vzdalenost; } for (int pres = 0; pres < count; pres++) for (int z = 0; z < count; z++) for (int kam = 0; kam < count; kam++) if (dist[z, kam] > dist[z, pres] + dist[pres, kam]) dist[z, kam] = dist[z, pres] + dist[pres, kam]; for (i = 0; i < count; i++) { for (j = 0; j < count; j++) Console.Write("{0}\t", dist[i, j]); Console.WriteLine(); } } } }