示例#1
0
    private static void Main()
    {
        var output    = new StringBuilder();
        int testCount = FastIO.ReadNonNegativeInt();

        for (int t = 0; t < testCount; ++t)
        {
            int cityCount   = FastIO.ReadNonNegativeInt();
            var cityIndices = new Dictionary <string, int>(cityCount);
            var cityGraph   = new List <KeyValuePair <int, int> > [cityCount];

            for (int c = 0; c < cityCount; ++c)
            {
                cityIndices.Add(FastIO.ReadString(), c);
                cityGraph[c] = new List <KeyValuePair <int, int> >();

                int neighborCount = FastIO.ReadNonNegativeInt();
                for (int n = 0; n < neighborCount; ++n)
                {
                    int neighborIndex  = FastIO.ReadNonNegativeInt() - 1;
                    int connectionCost = FastIO.ReadNonNegativeInt();

                    cityGraph[c].Add(new KeyValuePair <int, int>(neighborIndex, connectionCost));
                }
            }

            int pathCount = FastIO.ReadNonNegativeInt();
            for (int p = 0; p < pathCount; ++p)
            {
                int sourceCity      = cityIndices[FastIO.ReadString()];
                int destinationCity = cityIndices[FastIO.ReadString()];

                output.Append(
                    SHPATH.Solve(cityGraph, sourceCity, destinationCity));
                output.AppendLine();
            }
        }

        Console.Write(output);
    }