示例#1
0
    static object Solve()
    {
        var(n, m) = Read2();
        var es = GraphConsole.ReadEdges(m);
        var k  = int.Parse(Console.ReadLine());
        var p  = Read();

        var map   = new UnweightedMap(n + 1, es, true);
        var map_r = new UnweightedMap(n + 1, Array.ConvertAll(es, e => e.Reverse()), true);

        var r = map_r.Bfs(p.Last());

        var(min, max) = (0, 0);

        for (int i = 0; i < k - 1; i++)
        {
            if (r[p[i]] <= r[p[i + 1]])
            {
                min++;
                max++;
            }
            else
            {
                if (map[p[i]].Count(v => r[v] < r[p[i]]) > 1)
                {
                    max++;
                }
            }
        }
        return($"{min} {max}");
    }
示例#2
0
    static void Main()
    {
        var(n, m, k) = Read3();
        var a   = Read();
        var es  = Array.ConvertAll(new bool[m], _ => (Edge)Read());
        var map = new UnweightedMap(n + 1, es, false);

        var set     = a.ToHashSet();
        var already = es.Any(e => set.Contains(e.From) && set.Contains(e.To));

        if (already)
        {
            var r1 = map.Bfs(1, n);
            Console.WriteLine(r1[n]);
        }
        else
        {
            var r1 = map.Bfs(1, -1);
            var rn = map.Bfs(n, -1);

            long M = 0, M1 = -1;
            var  vs = a.Select(i => (i, d: r1[i] - rn[i])).OrderBy(v => v.d);
            foreach (var(i, _) in vs)
            {
                if (M1 != -1)
                {
                    M = Math.Max(M, M1 + rn[i]);
                }
                M1 = Math.Max(M1, r1[i]);
            }
            M++;
            Console.WriteLine(Math.Min(r1[n], M));
        }
    }